Using book code with Access 2007 .accdb files
I am trying to work through the book using VS2010 and Access 2007 Northwind database file. I have coded the following and keep getting an error that
No value given for one or more required parameters.
The error is thrown when the code reaches the objDataAdapter.Fill(objDataTable) line before entering the for each loop.
Thanks in advance for any help.
***************Code Below*****
Dim strConnectionString AsString = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=C:\Northwind 2007.accdb;"
Dim objConnection AsNewOleDbConnection(strConnectionString)
Dim strSQL AsString = "SELECT FirstName, LastName FROM Employees"
Dim objCommand AsNewOleDbCommand(strSQL, objConnection)
Dim objDataAdapter AsNewOleDbDataAdapter(objCommand)
Dim objDataTable AsNew Data.DataTable("Employees")
Dim objDataRow AsDataRow
Try
'Open the database connection
objConnection.Open()
'Fill the DataTable object
objDataAdapter.Fill(objDataTable)
'Load the list box
ForEach objDataRow In objDataTable.Rows
lstName.Items.Add(objDataRow.Item("FirstName") & " " & objDataRow.Item("LastName"))
Next
Catch OleDbExceptionErr AsOleDbException
'Write the exception
Debug.WriteLine(OleDbExceptionErr.Message)
Catch InvalidOperationExceptionErr AsInvalidOperationException
'Write the exception
Debug.WriteLine(InvalidOperationExceptionErr.Message)
EndTry
|