嗨,我是 Visual Basic 的新手。我有一个按钮,当它被点击时,它会通过用户输入的 ID 找到学生,并将数据输出到文本字段。我不太确定我这样做是否正确。因为我收到此错误 [图片] >> http://img812.imageshack.us/img812/7650/gq0z.png
顺便说一句,到目前为止,这是我的代码。有人能帮助我吗?谢谢!
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