Im trying to select data from a MS access database, i have done this for SQL server before with no problem, but now with a Access database i get a run time error for "No value given for one or more required parameters".
Below is my code
Private Sub ViewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewToolStripMenuItem.Click
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim ds As New DataSet
Dim dt As New DataTable
Dim da As New OleDbDataAdapter
Try
cn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=I:\doc_cntl\Doc_Control Lists\MS Access Logs\2009 MDL_be.accdb;Persist Security Info=False;")
'provider to be used when working with access database
cn.Open()
cmd = cn.CreateCommand
cmd.CommandText = "SELECT * FROM [2009 MDL 2] WHERE [DocumentPartNumber] = '" & Trim(txtPartNumber.Text) & "'"
da.SelectCommand = cmd
da.Fill(ds, "[2009 MDL 2]")
dt = ds.Tables("[2009 MDL 2]")
TextBox1.Text = ds.Tables(0).Rows(0).Item("DrawingLocation").ToString
TextBox2.Text = ds.Tables(0).Rows(0).Item("DocumentPartNumber").ToString
cn.Close()
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")
End Try
End Sub
Thanks for your help in advance.