DropDownlist PostBack Question

  • Thread starter Patrick Olurotimi Ige
  • Start date
P

Patrick Olurotimi Ige

Hi DevGuy thx for the reply but using:-
Cmd.Parameters.Add(New SqlParameter("@DebtorCodeID",
ddlGetDebtor.SelectedItem.Value.ToString))

Still give the same error!!!

Whereas Charmis advice is good but in my case i'm using
NextResults() like so below:-

How should i use the

If DropDown.SelectedIndex > 0 Then
EndIf


Without affecting the "objDR.NextResult()"



Code Below:--
------------------
Try

MyConn.Open()


objDR = Cmd.ExecuteReader

ddlFill1.DataSource = objDR
ddlFill1.DataValueField = "AddressID"
ddlFill1.DataTextField = "Suburb"
ddlFill1.DataBind()

objDR.NextResult()




ddlFill2.DataSource = objDR
ddlFill2.DataValueField = "AddressID"
ddlFill2.DataTextField = "Suburb"
ddlFill2.DataBind()
'ddlFill2.Items.Insert(0, "-Select Delivey Address-")

objDR.NextResult()


With ddlFill3
.DataSource = objDR
.DataValueField = "AddressID"
.DataTextField = "Suburb"
.DataBind()
'ddlFill3.Items.Insert(0, "-Select Billing Address-")
End With

objDR.NextResult()

With ddlFill4
.DataSource = objDR
.DataValueField = "TelstraAccID"
.DataTextField = "TelstraAccNo"
.DataBind()
End With

ddlFill1.Items.Insert(0, "-Select Site Address-")
ddlFill2.Items.Insert(0, "-Select Delivey Address-")
ddlFill3.Items.Insert(0, "-Select Billing Address-")



Catch ex As SqlException
Response.Write(ex.ToString)
Finally

If Not (objDR Is Nothing) Then
objDR.Close()

End If

MyConn.Dispose()
End Try

the error is :-
DebtorCodeID is an integer
But when somebody selects a Value and does a Postback and gets back to
"Select Debtor Code" and select it it RETURNS an error!:-

System.Data.SqlClient.SqlException: Error converting data type nvarchar
to int. at
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at
System.Data.SqlClient.SqlCommand.ExecuteReader() at
Online_Ordering.CheckOut.FillAll(Object sender, EventArgs e) in
c:\inetpub\wwwroot\Online_Ordering\CheckOut.aspx.vb:line 209
 
G

Guest

I now believe your problem is on the database side. Look at the error, it is
trying to convert nvarchar to an integer. You can't do that. how can you
make 'jkl43' to an integer? Also, you may find varchar a better choice
unless you need unicode (other languages) in your database. I would start by
replicating things in sql query. Take a look at what is happening on the
SQl side. also you can try using a dummy variable to force a type on the
value pulled from the dropdown. Good luck, you'll get it.

Dim strddlGetdebtor as string
strddlGetdebtor = ddlGetDebtor.SelectedItem.Value.ToString
Cmd.Parameters.Add(New SqlParameter("@DebtorCodeID",
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,823
Latest member
Nadia88

Latest Threads

Top