Hello everyone,
Dim SI As String = ""
SI = CheckedListBox1.SelectedItem
Dim TextcommandSQL As String = ""
Dim myCOLUMN As String = ""
myCOLUMN = ComboBox1.SelectedItem
TextcommandSQL = "SELECT * FROM test_table where " & myCOLUMN & " = " & SI
MsgBox(TextcommandSQL)
Dim con As New SqlConnection
con.ConnectionString = (" Data Source=i7borgmatrix2\sqlexpress;Initial Catalog=TextSQL;Integrated Security=True")
Dim queryString As String = TextcommandSQL
Using connection As New SqlConnection(con.ConnectionString)
Dim command As New SqlCommand(queryString, connection)
connection.Open()
Dim reader As SqlDataReader = command.ExecuteReader()
Try
While reader.Read()
Console.WriteLine(String.Format("{0}, {1}", _
reader(0), reader(1)))
End While
Finally
' Always call Close when done reading.
reader.Close()
End Try
End Using
i am trying to use var. to tell sql what column and what row to search for in the db.
the user will select a column from a combobox <ie. weekday> and then select the item <ie. Tuesday>
then click the button to send the query to sql.
at the moment i am getting the error that the column "tuesday" or what ever day i select does not exist, when the day should be the day the sql searches for.!
Thank you for reading. :-)