Hi, I know that there have been a lot of questions on this topic and I have followed the solutions however my code still does not work. No error comes up, even after using Try and Catch and the code does not break, but the values are just not in the textboxes. It worked a few times but I must have changed the code slightly somewhere and now it no longer works.
I am trying to read the Subjects from the Subjects table in the database, depending on the StudentID that I have previously read. The StudentID gets read from the database and inserted into a textbox, no problem, but the subjects do not work. I have even tried the query in Access and it returns the results that I want.
If anyone could shed any light on why this does not work in VB, that would be great.
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\UserDatabase.accdb;" Using conn As OleDbConnection = New OleDbConnection(connString) Dim cmd As New OleDbCommand( _ "SELECT * FROM Subjects WHERE [StudentID]= '" & StudentID.Text & "'", conn) conn.Open() Dim rd As OleDbDataReader = cmd.ExecuteReader() Try If rd.HasRows() Then rd.Read() cmd.Parameters.AddWithValue("Subject1", Subject_1TextBox.Text).ToString() cmd.Parameters.AddWithValue("Subject2", Subject_2TextBox.Text).ToString() cmd.Parameters.AddWithValue("Subject3", Subject_3TextBox.Text).ToString() cmd.Parameters.AddWithValue("Subject4", Subject_4TextBox.Text).ToString() End If Catch ex As Exception MessageBox.Show(ex.Message & " - " & ex.Source) Finally End Try