Searching for specific row in the Access database which returns value to textboxes in vb2010 RRS feed

  • Question

  • Can anybody help me out!

    I am working on a project in vb2010 using MS access as database with table customers and field CustomerID(Primary key), CompanyName, Address, etc. Please i urgently need a code that searches for a specific record in access database, based on primary key entered, and it will returns value to textboxes.

    Urgent answer will highly appreciated. tanks

    Saturday, August 4, 2012 10:34 AM


  • Below is a relatively simple example. You just need to include the primary key fields in the WHERE clause of the SQL statement and add the corresponding parameters to the Command Parameters collection:

            Dim AccessConnection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" & _
        "Data Source=C:\Test Files\db1 XP.mdb")
            Dim SearchVal As String = "SomeValue"
            Dim AccessCommand As New OleDbCommand("SELECT [Field1], [Field2], [Field3] FROM Table5 WHERE [Field2] = @Param1", AccessConnection)
            AccessCommand.Parameters.AddWithValue("@Param1", SearchVal)
            Dim AccessDataReader As OleDbDataReader = AccessCommand.ExecuteReader(CommandBehavior.SequentialAccess)
            While AccessDataReader.Read()
            End While

    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Marked as answer by Allen_MSDN Monday, August 13, 2012 1:35 AM
    Monday, August 6, 2012 12:53 PM