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)
con.Open()
cmd.ExecuteNonQuery()
End Using
End Using
End Sub
Open in new window