No value given for one or more required parameters

nerazzuri

Member
Joined
Jan 12, 2010
Messages
7
Programming Experience
Beginner
I created a project in vb.net which is connected with database.
The problem appeared when i changed the path which connect with the database, i made it relative.
So some of the forms which contain the connection are working properly but in one form i got this error:

OLEDBExceptiona was unhundled
"No value given for one or more required parameters."

this error appears in this code

"cmd.ExecuteNonQuery()"

so pls if someone knows where is the problem tell me thnx.
 
Public Class CheckIn
Dim conn As New OleDbConnection(connection)
Private strPrintRecord As String
Private WithEvents dialogsprintdocument As PrintDocument

Private Sub btnCheckIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheckIn.Click
Dim a As Boolean

Dim cmd As OleDbCommand = New OleDbCommand("SELECT IDNumber, Name, Surname, Address, RoomNumber FROM tblGuests", conn)

Dim da As OleDbDataAdapter = New OleDbDataAdapter
Dim ds As DataSet = New DataSet

conn.Open()
cmd.ExecuteNonQuery()
conn.Close()

da.SelectCommand = cmd
a = da.Fill(ds)

frmGuests.DataGridView1.DataSource = ds.Tables(0)

If a = True Then
MessageBox.Show("Guest is checked inn")
Else
MessageBox.Show("reservation incomplete")

End If

End Sub


Also i have created a mudule that connect to database.
 
Why are you calling ExecuteNonQuery at all? Your SQL code contains a SELECT statament, which is a query. Also, you're executing that query and populating a DataTable with the results a couple of lines later. Get rid of these three lines:
VB.NET:
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
 
Why are you calling ExecuteNonQuery at all? Your SQL code contains a SELECT statament, which is a query. Also, you're executing that query and populating a DataTable with the results a couple of lines later. Get rid of these three lines:
VB.NET:
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()

I removed them now i am getting an error at a=da.fill(ds)
with this subject: No value given for one or more required parameters.(The same) ??
 
This is the module that i use for the connection with database:
Here is the connection module is the same for all forms.

Module Koneksioni
Dim baza As String = "..\..\db1.mdb"
Public connection As String = "provider=microsoft.jet.oledb.4.0; data source=" & baza & ""
End Module
 
I'm guessing that one of your column names is a reserved word. It could only be Name or Address, or maybe both. Try wrapping them in brackets, i.e. [], and see if that fixes the issue. It's always a good idea to avoid reserved words as identifiers if possible.
 
I'm guessing that one of your column names is a reserved word. It could only be Name or Address, or maybe both. Try wrapping them in brackets, i.e. [], and see if that fixes the issue. It's always a good idea to avoid reserved words as identifiers if possible.

I tried it but is the same error.
If i delete a=da.fill(ds) the program is running without errors but it's not filling the table it appears another table just with the information i typed at the moment and if i close they are lost.

What kind of value to give at a=da.fill(ds) ?????
 
Can you show the exact code you're using now?

It's the same i just deleted as you say

conn.Open()
cmd.ExecuteNonQuery()
conn.Close()

and if i delete a=da.fill(ds) is working without errors but it's not saving the informations, if i not delete this shows me an error that i must give a value !!
 
Did you read post #7? Did you do what I suggested? If so then your code has changed apart from that. Please post the exact code you're using now, to ensure that there are no misunderstandings.
 
Private Sub btnCheckIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheckIn.Click

Dim a As Boolean

Dim cmd As OleDbCommand = New OleDbCommand("SELECT IDNumber, [ Name ], Surname, [ Address ], RoomNumber FROM tblGuests", conn)

Dim da As OleDbDataAdapter = New OleDbDataAdapter
Dim ds As DataSet = New DataSet


da.SelectCommand = cmd
a = da.Fill(ds, "dataset")

frmGuests.DataGridView1.DataSource = ds.Tables()

If a = True Then
MessageBox.Show("Guest is checked inn")
Else
MessageBox.Show("reservation incomplete")

End If

end sub


This is the code.

If you know a different way how to select some textboxes from the form checkin and to show the information in another form which have a data grid view and is connected with database you can tell me.
 
Read the DW2 link in my signature, section Creating a Simple Data App

It will take you about 20 mins to go through the tutorial and at the end of it you'll have an app that conencts to a db, downloads and saves data. It might even show related data.. Much easier than the days you've spent on this so far!
 

Latest posts

Back
Top