Data Adapter OleDbException was Unhandled

ucp8

Active member
Joined
Feb 9, 2009
Messages
28
Programming Experience
3-5
Hi,

I am using Database connections to create lots of datasets in a project that I am currently working on. I have found one problem with one of my datasets which hasnt occured for the others though:

VB.NET:
[SIZE="2"]' Set database connection
        pupilNameConnect.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = F:\Software engineering project\SchoolTestProgram\SchoolTestDatabase.mdb"
        ' Open database connection
        pupilNameConnect.Open()
        ' Set the sql string
        pupilNameSql = "SELECT PupilDetails.[FirstName], PupilDetails.[Surame] FROM PupilDetails"
        ' Initialise data adapter
        pupilNameDa = New OleDb.OleDbDataAdapter(pupilNameSql, pupilNameConnect)
        ' Fill dataset with pupil information
        [COLOR="Red"]pupilNameDa.Fill(pupilNameDs, "PupilNames")[/COLOR]
        ' Instantiate noOfPupils
        noOfPupils = pupilNameDs.Tables("PupilNames").Rows.Count

        ' Add each pupil in the databases' name to the combo box
        For i = 0 To noOfPupils - 1
            cboSelectPupil.Items.Add(pupilNameDs.Tables("currentPupil").Rows(i).Item("FirstName").ToString + " " + pupilNameDs.Tables("currentPupil").Rows(i).Item("Surame").ToString)
        Next[/SIZE]

I get "OleDbException was Unhandled - No value given for one or more required parameters." at the red line.

The only difference in this initial setup from the others I have created is that this time round I am not specifying a WHERE clause in the SQL statement.

Can anyone see where the exception is arising from?

Thanks for the help!
 
Why don't you trap the error with:

VB.NET:
        Try

                'Your code here

        Catch ex As Exception

                 MsgBox(ex.StackTrace)

        End Try
 
Trapping the exception will not help here as I need to fill the Dataset using pupilNameDa.Fill(pupilNameDs, "PupilNames").

I cannot understand why it is throwing this exception. It says that 'No value has been given for one or more required parameters', but I have used the exact same setup for every other Dataset I have used and they all work.

Can anybody see where I am going wrong here?
 
Rookie mistake guys... I fed it the wrong string value for the Surname field. I uess that happens when you are coding at 4am in the morning :(
 
I was going to say.. it doesnt look like your SQL contains any parameters. Check that you have spelled all the column names correctly
 
Back
Top