0

I have VB.net project in which i need to search using a urno and it should populate info in all the textboxes and combo boxes that are on the form and it is the same form from which the data is stored in the database.here is the code

Public Class MBAUpdate
    Dim con As New OleDb.OleDbConnection()
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            'Dim da As OleDb.OleDbDataAdapter
            Dim dbprovider As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Taher\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\Database1.accdb;Persist Security Info=False;"
            Me.con = New OleDb.OleDbConnection()
            con.ConnectionString = dbprovider
            con.Open()

            Dim sqlquery As String = "SELECT * FROM MBA WHERE urno=" & CInt(txtb1.Text) & ";"
            Dim sqlcommand As New OleDb.OleDbCommand(sqlquery, con)
            Dim ds As DataSet

            With sqlcommand
                .CommandText = sqlquery
                .Connection = con
                .ExecuteReader()
            End With

            ' MsgBox("Record Added")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub
End Class

any ideas how to achieve this did quite googling did'nt help either....

4

1 回答 1

0

找到了一种方法来做到这一点,它的工作就像一个魅力......

Public Class MBAUpdate
    Dim con As New OleDb.OleDbConnection

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            'Dim da As OleDb.OleDbDataAdapter
            Dim dbprovider As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Taher\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\Database1.accdb;Persist Security Info=False;"
            Me.con = New OleDb.OleDbConnection
            Dim sqlquery As String = "SELECT * FROM MBA WHERE urno=" & CInt(txtb1.Text) & ";"
            Dim command As New OleDb.OleDbCommand(sqlquery, con)
            Dim reader As OleDb.OleDbDataReader
            con.ConnectionString = dbprovider
            con.Open()

            reader = command.ExecuteReader()
            reader.Read()

            txtName.Text = reader(1).ToString()
            txtFname.Text = reader(2).ToString()
            txtCAdd.Text = reader(3).ToString()
            txtPAdd.Text = reader(4).ToString()
            txtEid.Text = reader(5).ToString()
            cmbGender.Text = reader(6).ToString()
            txtMno.Text = reader(7).ToString()




            ' MsgBox("Record Added")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub
End Class
于 2013-02-20T17:06:12.253 回答