troubleshooting Question

MS Visual Studio 2017 and MS Access: Retrieve records based on query parameters

Avatar of Maslow Raffo
Maslow Raffo asked on
Visual Basic.NETMicrosoft AccessMicrosoft Visual Studio
23 Comments2 Solutions134 ViewsLast Modified:
I'm using MS Visual Studio 2017, VB.NET,  and connecting to an MS Access database.
I can write to the database (see code below), but I can't find online examples or instructions how to query the database (i.e., I type in a DOB and it returns all the people in the database with that DOB).

The DB has the following tables/fields:
Table = "patient"
Fields = ptid, fname, lname, dob

I want to type a dob into the text field on my form, press a button, and have it return the fname and lname of any record that has that DOB.  Thanks!

************This Works to write to the database.****************
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim con As New OleDb.OleDbConnection

        con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\tleng\source\repos\WindowsApp3\WindowsApp3\db1.accdb"

        Dim SqlString As String = "Insert into [patient] (ptid, fname, lname, dob) Values (idtextbox, fnametextbox, lnametextbox, dobdatetimepicker)"

        Using conn As New OleDb.OleDbConnection(con.ConnectionString)

            Using cmd As New OleDb.OleDbCommand(SqlString, con)

                cmd.CommandType = CommandType.Text
                cmd.Parameters.AddWithValue("column", IDTextBox.Text)
                cmd.Parameters.AddWithValue("column", FnameTextBox.Text)
                cmd.Parameters.AddWithValue("column", LnameTextBox.Text)
                cmd.Parameters.AddWithValue("column", DobDateTimePicker.Text)

            End Using
        End Using
    End Sub
Join our community to see this answer!
Unlock 2 Answers and 23 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 23 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros