开发者

how to retrieve data from database using select query

I have to retrieve data in two TextBoxes but the data should belong to tokennum that I am getting from first text box. I have a total of three TextBoxes and one button. In a database called db1 I have a table named Table1 and two fields ser as serial number, tokennum for token number and name for name of employees.

Private Sub Button1_Click(ByVal sender As System.Object, By开发者_JS百科Val 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 sir:thanks for guidance,i corrected that but now how to proceed?how to get respective data in the correspoding textboxes?


Your sql query is wrong

    sql = "SELECT Table1.ser FROM Table1 where Table1.token num=a"

It should be something like this :

    sql = "SELECT Table1.ser FROM Table1 where Table1.tokennum=" & a

Although the 'Table1.token num' is wrong, there cannot be a space within a column name, I hope that was just a typo and have corrected the same in the second query.


"SELECT Table1.ser FROM Table1 where Table1.tokennum= " + a

This is a start, but your question is not very clear

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜