我必须在两个TextBox中检索数据,但数据应属于我从第一个文本框获取的tokennum
。我总共有三个TextBox和一个按钮。在名为db1
的数据库中,我有一个名为Table1
的表和两个字段ser
作为序列号,tokennum
表示令牌号,name
表示员工姓名。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Dim a As Integer
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = C:\Documents and Settings\trainee-ng-it\Desktop\Subhedar Sir\New Folder (2)\db1.mdb"
con.ConnectionString = dbProvider & dbSource
con.Open()
a = Val(TextBox1.Text)
sql = "SELECT Table1.ser FROM Table1 where Table1.token num=a"
da = New OleDb.OleDbDataAdapter(sql, con)
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "db1")
MsgBox("Database is now open")
con.Close()
MsgBox("Database is now Closed")
End Sub
End Class
@dhruva先生:感谢您的指导,我更正了但现在该怎么办?如何在对应的文本框中获取相应的数据?
答案 0 :(得分:0)
您的SQL查询错误
sql = "SELECT Table1.ser FROM Table1 where Table1.token num=a"
它应该是这样的:
sql = "SELECT Table1.ser FROM Table1 where Table1.tokennum=" & a
虽然'Table1.token num'错误,但列名中不能有空格,我希望这只是一个拼写错误,并在第二个查询中更正了相同内容。
答案 1 :(得分:0)
"SELECT Table1.ser FROM Table1 where Table1.tokennum= " + a
这是一个开始,但你的问题不是很清楚