Ok what is wrong with this code? I am trying to bind a record to a textbox using a Dropdown selected index change. I get the error, any help would be greatly appreciated. if there is a better way to do this I am open to anything at this point as I've spent considerable time on google and other forums looking for a solution. Thanks in advance!
Conversion failed when converting the nvarchar value 'DrFirstName DrLastName,Ph.D.' to data type int. is it because I concatenate the name and prefix of the DR into the Dropdown list like this,
Here is the dropdownlist code that I want to populate the textbox with the emailaddress in the table associated with Dr name and ID.Code:SELECT ID,EmailAddress, DrName + ',' + PreFix AS DrName FROM DrNames
Code:Private Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged Dim dt As New DataTable() If DropDownList1.SelectedItem.Text = "OTHER,..." Then txtRx1.Visible = True DropDownList1.Visible = False End If Dim connString As String = ConfigurationManager.ConnectionStrings("TCONNConnectionString").ConnectionString Dim con As New SqlConnection(connString) Dim cmd As New SqlCommand Dim strQuery As String = "SELECT ID, EmailAddress, DrName from DrNames WHERE DrName = @DrName" cmd.Parameters.AddWithValue("@DrName", DropDownList1.SelectedItem.Value) cmd.CommandType = CommandType.Text cmd.CommandText = strQuery MsgBox(strQuery) cmd.Connection = con Try con.Open() Dim sdr As SqlDataReader = cmd.ExecuteReader() While sdr.Read() txtEmailAddress.Text = sdr("EmailAddress").ToString() End While Catch ex As Exception Throw ex Finally con.Close() con.Dispose() End Try End Sub




Reply With Quote
