I have an error in my code which states:
System.Data.SqlClient.SqlException: Conversion failed when converting the varchar value '(ListBox1.SelectedValue.ToString)'
to data type int. at System.Data.SqlClient.SqlConnection
Can anyone help me why this is happening. im using web developer express.
My purpose is to delete the row when i click the delete button. firstname is displayed on a textbox when i click on the
listbox and ID is the value that is not displayed on the listbox.
Also how can i display the remaining details into the textboxes since i can only display one detail into one of the textboxes.
System.Data.SqlClient.SqlException: Conversion failed when converting the varchar value '(ListBox1.SelectedValue.ToString)'
to data type int. at System.Data.SqlClient.SqlConnection
Can anyone help me why this is happening. im using web developer express.
VB.NET:
Protected Sub DeleteButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim DBConn As New Data.SqlClient.SqlConnection("Data Source=XXX;Initial Catalog=XXX;Integrated Security=True")
Dim DBCmd As New Data.SqlClient.SqlCommand
Dim DBAdap As New Data.SqlClient.SqlDataAdapter
Dim DS As New Data.DataSet
DBConn.Open()
Try
DBCmd = New Data.SqlClient.SqlCommand("DELETE FROM family WHERE firstname = '" & TextBox2.Text & "' AND ID =
'(ListBox1.SelectedValue.ToString)'", DBConn)
DBCmd.ExecuteNonQuery()
Response.Write("Your record is deleted")
DBAdap = New Data.SqlClient.SqlDataAdapter("SELECT * FROM family", DBConn)
DBAdap.Fill(DS)
ListBox1.DataBind()
Catch exp As Exception
Response.Write(exp)
End Try
DBCmd.Dispose()
DBAdap.Dispose()
DBConn.Close()
DBConn = Nothing
End Sub
listbox and ID is the value that is not displayed on the listbox.
Also how can i display the remaining details into the textboxes since i can only display one detail into one of the textboxes.
VB.NET:
Protected Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles
ListBox1.SelectedIndexChanged
TextBox1.Text = ListBox1.SelectedItem.ToString
End Sub
Last edited by a moderator: