我必須檢索兩個文本框中的數據,但數據應該屬於我從第一個文本框獲得的tokennum
。我總共有三個文本框和一個按鈕。在名爲db1
的數據庫中,我有一個名爲Table1
的表和兩個字段ser
作爲序列號,tokennum
作爲令牌號,name
作爲僱員的名稱。如何使用select查詢從數據庫檢索數據
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先生:感謝您的指導,我糾正了,但現在如何進行如何把對應的文本框中得到相應的數據?
也許你還沒有使用Sqlcommand.ExecuteScalar過嗎? – 2014-01-02 00:36:53