hi im new in Visual basic. I have a button that when its clicked, its gonna find the student via their ID inputted by the user and its gonna output the data to the textfields. I'm not pretty sure if im doing this right. because i'm getting this error [image] >> http://img812.imageshack.us/img812/7650/gq0z.png
btw here's my code so far. can someone help me please? thanks!
cmd.CommandText = "Select * from Student where Student_id = '" & id.Text & "'"
cmd.Connection = db
dr = cmd.ExecuteReader
Try
dr.Read()
id.Text = dr.GetValue(0)
Lname.Text = dr.GetValue(1)
Fname.Text = dr.GetValue(2)
Mname.Text = dr.GetValue(3)
datet.Text = dr.GetValue(4)
age.Text = dr.GetValue(5)
male.Text = dr.GetValue(6)
female.Text = dr.GetValue(7)
status.Text = dr.GetValue(8)
staddress.Text = dr.GetValue(9)
cityAdd.Text = dr.GetValue(10)
dr.Close()
Catch ex As Exception
MsgBox("" + ex.Message)
dr.Close()
End Try
id.Textis empty you will get an error; you will also want to convert the text it contains to a number before you build the SQL. In the future post the actual error message (they are important info) rather than a link to a pictureIf NOT isdbnull(dr.getvalue(0))... for each one obviously incrementing the getvalue number for each one.dr.getvalue(n)todr.getvalue("nameOfColumn"). Its a better habit.dr.item("nameofcolumn")a bit shorter... see answer below