How to populate dataset with Access

  • Thread starter Thread starter Sasha
  • Start date Start date
S

Sasha

Hi All,

I am new to VB.Net and am having a problem with the below code. I am
trying to fill in a datagrid with the below query but it keeps giving
me error where the *'s are located below. I have an OleDbDataAdapter,
OleDbConnection and DataSet on my form. Am I supposed to do something
with dataset before it is populated?

This is the actual error:
An unhandled exception of type 'System.Data.OleDb.OleDbException'
occurred in system.data.dll


Thanks
Mathew


Private Sub frmGetData_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim result
OleDbDataAdapter1.SelectCommand.CommandText = "SELECT
JobTitle, PrimaryJob.* FROM PrimaryJob WHERE JobTitle ='" & gStrTitle
& "'"
ProdDataSet.Clear()
*** OleDbDataAdapter1.Fill(ProdDataSet)***
End Sub
 
Sasha:
wrap the DataAdapter.Fill line in a Try Catch

Try
OleDbDataAdapter1.Fill(ProdDataSet)
Catch ex as OleDbException
Debug.Assert(false, ex.ToString)
End Try

See what the assertion says. The likely culprits are something wrong with
the connection string or connection or something with the syntax.

Also, instead of string concatenation you may want to opt for Parameters..

....Where JobTitle = ?

then OleDbDataAdapter1.SelectCommand.Parameters.Add(gStrTitle)
 
Sasha,
Well, you will have JobTitle returned twice. You could just try
SELECT * FROM PrimaryJob WHERE ......
and see if that works.

Ron Allen
 
Back
Top