Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
con.Open()
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT * FROM guestdatabase "
dr = cmd.ExecuteReader
While (dr.Read())
Dim nems = dr.GetString("Name")
Visitor.Items.Add(nems)
End While
Catch ex As Exception
MessageBox.Show(ex.Message)
con.Close()
End Try
End Sub
Private Sub Fname_TextChanged(sender As Object, e As EventArgs) Handles Fname.TextChanged
Try
con.Close()
con.Open()
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT * FROM residents WHERE FirstName = '" & Fname.Text & "'"
dr = cmd.ExecuteReader
If Not dr Is Nothing Then
dr.Read()
Lname.Text = dr("LastName").ToString
dr.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
con.Close()
End Try
End Sub
我想在1个表单中同时调用来自不同表的数据,但是它表示“从组合框调用Read()1之前访问字段的无效尝试和文本框中的1请求帮助:3提前谢谢