Why i get error like this : "Syntax error in query expression"

Prince29

Member
Joined
Sep 15, 2015
Messages
10
Programming Experience
Beginner
What wrong with my code ? here's my code :

Try
Connection.Open()
Dim query As String
query = ("SELECT * from RegistrationTable WHERE _Name = '" & ListBox1.Text & "'")


command = New OleDbCommand(query, Connection)
Reader = command.ExecuteScalar
While Reader.Read
txtPID.Text = Reader("PatientID")
txtName.Text = Reader("_Name")
txtAge.Text = Reader("_Age")
cmbGender.Text = Reader("_Gender")
txtPhone.Text = Reader("_Phone")
txtAddress.Text = Reader("_Address")
txtDisease.Text = Reader("_Disease")
ComboBox1.Text = Reader("_Building")
ComboBox2.Text = Reader("_RoomNo")
txtRT.Text = Reader("_Roomtype")










End While
Connection.Close()
Catch ex As Exception
MsgBox(ex.Message)


Finally
Connection.Dispose()
End Try
 
Sir JohnH

Hi,

This code is for getting the data from listbox and display to textbox . I already get the code for displaying the data to listbox and now i want to display it in textbox .

I can't understand what you said . can you explain or give example in vb.net ?
 
It is not about your controls, it is about using parameters with the query and command object. There are many VB.Net examples in that page that show how to use parameters.
 
Back
Top