1,105,384 Community Members

Error at dataset creation

Member Avatar
Galbatorix
Junior Poster in Training
52 posts since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,
I have an error with this function at runtime

     Private Sub adultPay()
    sql = "SELECT adultRate FROM roomType WHERE roomType = " & rumType.ToString & ""
    connectDatabase()
    Using da As New OleDb.OleDbDataAdapter(sql, con)
        Using ds As New DataSet
            Try
                da.Fill(ds, "AdultRate") 'error here
                Dim adultRate As String = ds.Tables("AdultRate").Rows(0).Item(0).ToString
                Dim adultTotal As Integer = txtNoOfAdults.Text * Val(adultRate)
                txtAdultTotal.Text = adultTotal.ToString
            Catch ex As Exception
                MessageBox.Show(ex.ToString, "error")
                Clipboard.SetDataObject(ex)
            End Try
            DisconnectDB()
        End Using
    End Using
End Sub

the function is supposed to change the value of the adult total textbox when the number of adults has been put.
The error is as below

System.Data.OleDb.OleDbException: No value given for one or more required parameters.
   at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
   at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
   at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
   at Albergo.frmCheckIn.adultPay() in C:\Users\gman\Documents\Visual Studio 2008\Projects\Albergo\Albergo\frmCheckIn.vb:line 111

The line 111 is the one in the sub wea u find
da.Fill(ds, "AdultRate")

Please help

Member Avatar
Begginnerdev
Veteran Poster
1,142 posts since Apr 2010
Reputation Points: 251 [?]
Q&As Helped to Solve: 191 [?]
Skill Endorsements: 15 [?]
 
0
 

Does rumType.ToString() return a value?

Step through the code in debug, and use intellisence to check if it does.

Member Avatar
Khristophor
Newbie Poster
1 post since Feb 2012
Reputation Points: 8 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
1
 

At first glance it looks like your SQL statement is not formatted correctly. I would check to see if the statement is being passed to SQL properly.

sql = "SELECT adultRate FROM roomType WHERE roomType = " & rumType.ToString & ""

Should look something like:

sql = "SELECT adultRate FROM roomType WHERE roomType = '" & rumType.ToString & "'"

(Missing ').

But as Begginerdev said above, use break points and step through your code.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article