Parameter error for executeNonQuery()

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2005
Posts: 41
Reputation: npasma is an unknown quantity at this point 
Solved Threads: 0
npasma's Avatar
npasma npasma is offline Offline
Light Poster

Parameter error for executeNonQuery()

 
0
  #1
Jun 27th, 2005
OK, yeah u guessed it. VBnoob here. Like so many other poor souls, lost in a sea of code...heres the dealio-

I know param's need to be completely done and in the correct order for executeNonQuery() to work, but here's my error:

Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters.

Source Error:

Line 88: DBConnection.Open()
Line 89: Dim iCount As Integer
Line 90: iCount = cmdSoftware.ExecuteNonQuery()
Line 91: DBConnection.Close()
Line 92: If iCount > 0 Then


Source File: c:\inetpub\wwwroot\ASPproject\WebApplication2\SoftwareDB.vb Line: 90

Stack Trace:

[OleDbException (0x80040e10): No value given for one or more required parameters.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +174
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +65
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +112
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +66
WebApplication2.SoftwareDB.updateEntry(Software Software) in c:\inetpub\wwwroot\ASPproject\WebApplication2\SoftwareDB.vb:90
WebApplication2.WebForm1.btnUpdate_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\ASPproject\WebApplication2\WebForm1.aspx.vb:251
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292


The relevant code is as follows:
  1. Public Shared Function updateEntry(ByVal Software As Software) As Boolean
  2. Dim sUpdate As String = "UPDATE [SOFTWARE DATABASE] SET " _
  3. & "SoftwareNum=@SoftwareNum, SoftwareName=@SoftwareName, Version=@Version, " _
  4. & "Location=@Location, SoftwareBrand=@SoftwareBrand, DatePurchased=@DatePurchased, " _
  5. & "FirstName=@FirstName, LastName=@LastName, SerialNumber=@SerialNumber, Model=@Model " _
  6. & "WHERE SoftwareNum=@SoftwareNum"
  7. Dim DBConnection As OleDbConnection = Connection()
  8. Dim cmdSoftware As New OleDbCommand(sUpdate, DBConnection)
  9. cmdSoftware.Parameters.Add("@SoftwareNum", Software.SoftwareNum)
  10. cmdSoftware.Parameters.Add("@SoftwareName", Software.SoftwareName)
  11. cmdSoftware.Parameters.Add("@Version", Software.Version)
  12. cmdSoftware.Parameters.Add("@Location", Software.Location)
  13. cmdSoftware.Parameters.Add("@SoftwareBrand", Software.SoftwareBrand)
  14. cmdSoftware.Parameters.Add("@DatePurchased", Software.DatePurchased)
  15. cmdSoftware.Parameters.Add("@FirstName", Software.FirstName)
  16. cmdSoftware.Parameters.Add("@LastName", Software.LastName)
  17. cmdSoftware.Parameters.Add("@SerialNumber", Software.SerialNumber)
  18. cmdSoftware.Parameters.Add("@Model", Software.Model)
  19. DBConnection.Open()
  20. Dim iCount As Integer
  21. iCount = cmdSoftware.ExecuteNonQuery()
  22. DBConnection.Close()
  23. If iCount > 0 Then
  24. Return True
  25. Else
  26. Return False
  27. End If
  28. End Function

I dunno, looks like i have all the needed parameters to me. Am I missing something dumb here?
Last edited by Paladine; Jun 28th, 2005 at 3:31 am. Reason: Adding code blocks
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 41
Reputation: npasma is an unknown quantity at this point 
Solved Threads: 0
npasma's Avatar
npasma npasma is offline Offline
Light Poster

Re: Parameter error for executeNonQuery()

 
0
  #2
Jun 27th, 2005
This may clarify, I changed the UPDATE statement to be more accurate, what you see before each parameter there is the actual column names, many in brackets b/c they would otherwise be illegal in VB code. (I didn't name the little buggers.) The error I get is still the same. Am I allowed to have slightly diff. param names than the corresponding column names?

  1. Dim sUpdate As String = "UPDATE [SOFTWARE DATABASE] SET " _
  2. & "[Software #]=@SoftwareNum, [Software Name]=@SoftwareName, Version=@Version, " _
  3. & "Location=@Location, [Soft Brand]=@SoftwareBrand, DatePurchased=@DatePurchased, " _
  4. & "FirstName=@FirstName, LastName=@LastName, SerialNumber=@SerialNumber, Model=@Model " _
  5. & "WHERE SoftwareNum=@SoftwareNum"
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 27
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Parameter error for executeNonQuery()

 
0
  #3
Jun 28th, 2005
Well first off you have the second parameter of the Add Method containing the value you are passing in, and not the datatype. And you have not created any Parameter Objects , to store those parameter values for the SQL statement.

cmdSoftware.Parameters.Add("@SoftwareNum", Software.SoftwareNum)

should be
cmdSoftware.Parameters.Add("@SoftwareNum", SqlDataType.Int) 

for example.

Values are not passed into the query with parameters like that, but rather it should be done like this:

 Dim objNum as Parameter
objNum = cmdSoftware.Parameters.Add("@SoftwareNum", SqlDataType.Int) 
  objNum.Value = Software.SoftwareNum

Remember: Add method is a for the Parameters Collection. It is a collection of Objects that hold the values which you want to pass to the SQL Statement. But no where in your code do you pass these collection of Parameter Objects the values you want them to contain. The Add method takes two Parameters (empty string, sql or odbc Datatype). Take a look at the Parameters Collection Class (a blueprint for a parameter object).

Hope this helps.


**Note : You should use msdn.microsoft.com to research the methods & parameters those methods take, when you are coding, and check out the Tutorials on Daniweb....may just help!. **



Originally Posted by npasma
This may clarify, I changed the UPDATE statement to be more accurate, what you see before each parameter there is the actual column names, many in brackets b/c they would otherwise be illegal in VB code. (I didn't name the little buggers.) The error I get is still the same. Am I allowed to have slightly diff. param names than the corresponding column names?

  1. Dim sUpdate As String = "UPDATE [SOFTWARE DATABASE] SET " _
  2. & "[Software #]=@SoftwareNum, [Software Name]=@SoftwareName, Version=@Version, " _
  3. & "Location=@Location, [Soft Brand]=@SoftwareBrand, DatePurchased=@DatePurchased, " _
  4. & "FirstName=@FirstName, LastName=@LastName, SerialNumber=@SerialNumber, Model=@Model " _
  5. & "WHERE SoftwareNum=@SoftwareNum"
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 27
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Parameter error for executeNonQuery()

 
0
  #4
Jun 28th, 2005
FYI


By the way you do not add the [Software #] = @SoftwareNum into your Update Statement. It is your Primary Key value, so you wouldn't be updating it on the fly when using a where clause. Not proper Referential Integrity with that type of SQL update statement.


Originally Posted by npasma
This may clarify, I changed the UPDATE statement to be more accurate, what you see before each parameter there is the actual column names, many in brackets b/c they would otherwise be illegal in VB code. (I didn't name the little buggers.) The error I get is still the same. Am I allowed to have slightly diff. param names than the corresponding column names?

  1. Dim sUpdate As String = "UPDATE [SOFTWARE DATABASE] SET " _
  2. & "[Software #]=@SoftwareNum, [Software Name]=@SoftwareName, Version=@Version, " _
  3. & "Location=@Location, [Soft Brand]=@SoftwareBrand, DatePurchased=@DatePurchased, " _
  4. & "FirstName=@FirstName, LastName=@LastName, SerialNumber=@SerialNumber, Model=@Model " _
  5. & "WHERE SoftwareNum=@SoftwareNum"
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 13
Reputation: earlofroberts is an unknown quantity at this point 
Solved Threads: 1
earlofroberts earlofroberts is offline Offline
Newbie Poster

Re: Parameter error for executeNonQuery()

 
0
  #5
Jun 29th, 2005
I suspect that one of your parameters contains a NULL.
By the way, if you use imbedded code instead of stored procedures you are exposing yourself to hacking by injection.
good luck.

earlofroberts
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 41
Reputation: npasma is an unknown quantity at this point 
Solved Threads: 0
npasma's Avatar
npasma npasma is offline Offline
Light Poster

Re: Parameter error for executeNonQuery()

 
0
  #6
Jun 29th, 2005
Thank you all for your time in replying to my question. I am bogged down today, working on switching some servers from Novell to Windows NT (hooray!), but hopefully I'll be able to address these issues soon! Man, I'm glad I found this site. :mrgreen: Thanks again.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 41
Reputation: npasma is an unknown quantity at this point 
Solved Threads: 0
npasma's Avatar
npasma npasma is offline Offline
Light Poster

Re: Parameter error for executeNonQuery()

 
1
  #7
Jun 30th, 2005
OK, I'm back with modified code- but no dice. Same error. I changed the parameter entry stuff according to Paladine's advice, and I got my debugger working, and checked all 10 of my parameters- they all contain values, none of them are null. How then can I be getting this error? :surprised

  1. Public Shared Function updateEntry(ByVal prmSoftware As Software) As Boolean
  2. Dim sUpdate As String = "UPDATE [SOFTWARE DATABASE] SET " _
  3. & "[Software Name]=@SoftwareName, Version=@Version, " _
  4. & "Location=@Location, [Soft Brand]=@SoftwareBrand, DatePurchased=@DatePurchased, " _
  5. & "FirstName=@FirstName, LastName=@LastName, SerialNumber=@SerialNumber, Model=@Model " _
  6. & "WHERE SoftwareNum=@SoftwareNum"
  7. Dim DBConnection As OleDbConnection = Connection()
  8. Dim cmdSoftware As New OleDbCommand(sUpdate, DBConnection)
  9.  
  10. Dim prmSoftwareNum As OleDbParameter = cmdSoftware.Parameters.Add("@SoftwareNum", OleDbType.VarChar)
  11. Dim prmSoftwareName As OleDbParameter = cmdSoftware.Parameters.Add("@SoftwareName", OleDbType.VarChar)
  12. Dim prmVersion As OleDbParameter = cmdSoftware.Parameters.Add("@Version", OleDbType.VarChar)
  13. Dim prmLocation As OleDbParameter = cmdSoftware.Parameters.Add("@Location", OleDbType.VarChar)
  14. Dim prmSoftwareBrand As OleDbParameter = cmdSoftware.Parameters.Add("@SoftwareBrand", OleDbType.VarChar)
  15. Dim prmDatePurchased As OleDbParameter = cmdSoftware.Parameters.Add("@DatePurchased", OleDbType.VarChar)
  16. Dim prmFirstName As OleDbParameter = cmdSoftware.Parameters.Add("@FirstName", OleDbType.VarChar)
  17. Dim prmLastName As OleDbParameter = cmdSoftware.Parameters.Add("@LastName", OleDbType.VarChar)
  18. Dim prmSerialNumber As OleDbParameter = cmdSoftware.Parameters.Add("@SerialNumber", OleDbType.VarChar)
  19. Dim prmModel As OleDbParameter = cmdSoftware.Parameters.Add("@Model", OleDbType.VarChar)
  20. prmSoftwareNum.Value = prmSoftware.SoftwareNum
  21. prmSoftwareName.Value = prmSoftware.SoftwareName
  22. prmVersion.Value = prmSoftware.Version
  23. prmLocation.Value = prmSoftware.Location
  24. prmSoftwareBrand.Value = prmSoftware.SoftwareBrand
  25. prmDatePurchased.Value = prmSoftware.DatePurchased
  26. prmFirstName.Value = prmSoftware.FirstName
  27. prmLastName.Value = prmSoftware.LastName
  28. prmSerialNumber.Value = prmSoftware.SerialNumber
  29. prmModel.Value = prmSoftware.Model
  30.  
  31. DBConnection.Open()
  32. Dim iCount As Integer
  33. iCount = cmdSoftware.ExecuteNonQuery()
  34. DBConnection.Close()
  35. If iCount > 0 Then
  36. Return True
  37. Else
  38. Return False
  39. End If
  40. End Function

The error is:

Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters.

Source Error:


Line 135: DBConnection.Open()
Line 136: Dim iCount As Integer
Line 137: iCount = cmdSoftware.ExecuteNonQuery()
Line 138: DBConnection.Close()
Line 139: If iCount > 0 Then


Source File: c:\inetpub\wwwroot\ASPproject\WebApplication2\SoftwareDB.vb Line: 137

Stack Trace:


[OleDbException (0x80040e10): No value given for one or more required parameters.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
WebApplication2.SoftwareDB.updateEntry(Software prmSoftware) in c:\inetpub\wwwroot\ASPproject\WebApplication2\SoftwareDB.vb:137
WebApplication2.WebForm1.btnUpdate_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\ASPproject\WebApplication2\WebForm1.aspx.vb:248
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()


This error seems very persistant. I would appreciate any more help with this ongoing problem. I realize the code isn't very secure (vs. injection) yet, but the priority is solving this error first. Thank you!
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 27
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Parameter error for executeNonQuery()

 
0
  #8
Jun 30th, 2005
Try adding for each parameter, before the value assignment :

objParam.Direction = ParameterDirection.Input

Replace objParam with your parameter variable(s).

That may solve the problem
Last edited by Paladine; Jun 30th, 2005 at 1:32 pm. Reason: Forgot to say one thing
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 41
Reputation: npasma is an unknown quantity at this point 
Solved Threads: 0
npasma's Avatar
npasma npasma is offline Offline
Light Poster

Re: Parameter error for executeNonQuery()

 
0
  #9
Jul 6th, 2005
Well, after much effort I have stumbled on the solution. The problem was merely that my update statement, composed of a number of string parameters needed to have single quotes around each item. The code looks like this:

  1. Dim sUpdate As String = "UPDATE [SOFTWARE DATABASE] SET " _
  2. & "[Software Name]='@SoftwareName', Version='@Version', " _
  3. & "Location='@Location', [Soft Brand]='@SoftwareBrand', DatePurchased='@DatePurchased', " _
  4. & "FirstName='@FirstName', LastName='@LastName', SerialNumber='@SerialNumber' Model='@Model' " _
  5. & "WHERE SoftwareNum='@SoftwareNum'"

I'm not out of the woods yet, as I still have some other problems to deal with, but hey, another day another thread, right?

Thanks to those who assisted in solving this problem and a special thanks to Paladine, I never would have gotten this far without your help big guy. I can't believe you do this stuff for free! :cheesy:

Happy programming y'all.
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 27
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Parameter error for executeNonQuery()

 
0
  #10
Jul 6th, 2005
Well thanks for the compliments, I am just glad you figured it out (I should have noticed the quotes), and glad we were of any assistance!
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC