No value given for one or more required parameters.
-
Monday, March 05, 2012 2:58 PM
Is anyone able to help with the below code. i am receiving a
Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click
mystr = (
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\v369820\Desktop\DianosticChecker.mdb;Persist Security Info=False")
connection =
New OleDb.OleDbConnection(mystr)
connection.Open()
mydb =
"INSERT Into DianosticCheckResults (SocketsDB, FiltersDB) values (NumberOfSockets, NumberOfFilters)"
Dim run = New OleDb.OleDbCommand
' Try
run =
New OleDbCommand(mydb, connection)
run.ExecuteNonQuery()
'MsgBox("connection opened")
' Catch ex As Exception
'MsgBox(ex.Message, MsgBoxStyle.Critical, "Oledb Error")
' End Try
End Sub
No value given for one or more required parameters. and unable to find the issue.
All Replies
-
Tuesday, March 06, 2012 9:05 AM
hi,
your insert query needs literal values like this:
"INSERT Into DianosticCheckResults (SocketsDB, FiltersDB) values (21, 66)"
If NumberOfSockets and NumberOfFilters are integer variables, you could do this:
"INSERT Into DianosticCheckResults (SocketsDB, FiltersDB) values (" & NumberOfSockets.ToString() & ", " & NumberOfFilters.ToString() & ")"Regards, Nico
- Marked As Answer by Allen Li - AI3Microsoft Contingent Staff, Moderator Friday, March 09, 2012 1:58 AM
-
Tuesday, March 06, 2012 12:51 PM
I would highly recommend using Parameter arguments. NumberOfSockets and NumberOfFilters are being treated as string literals in the SQL statemement and cannot be identified and evaluated by the Jet database engine.
mydb = "INSERT Into DianosticCheckResults (SocketsDB, FiltersDB) values (?, ?)" Dim run = New OleDb.OleDbCommand run.Parameters.AddWithValue("Param1", NumberOfSockets) run.Parameters.AddWithValue("Param2", NumberOfFilters)Paul ~~~~ Microsoft MVP (Visual Basic)
- Proposed As Answer by Dan GuzmanMVP Tuesday, March 06, 2012 12:56 PM
- Marked As Answer by Allen Li - AI3Microsoft Contingent Staff, Moderator Friday, March 09, 2012 1:58 AM

