1

I am having issues trying to update my SQL database with code that should work, I am not seeing what is wrong, or how to fix it. Maybe a new set of eyes maybe able to point out what is wrong. Error =

"The parameterized query '(@0 nvarchar(3),@1 nvarchar(12),@2 nvarchar(8),@3 nvarchar(4),@4' expects the parameter '@8', which was not supplied."

Code is as Follows:

Truck_Number = Request.Form["Truck_Number"];
Truck_Make = Request.Form["Truck_Make"];        
Truck_Model = Request.Form["Truck_Model"];
Truck_Year = Request.Form["Truck_Year"];
Truck_Vin = Request.Form["Truck_Vin"];
Truck_Empty_Weight = Request.Form["Truck_Empty_Weight"];
Truck_Assigned_To = Request.Form["Truck_Assigned_To"];
Truck_Assigned_Date = Request.Form["Truck_Assigned_Date"];
Truck_Plate_Number = Request.Form["Truck_Plate_Number"];
Truck_IFTA_ID = Request.Form["Truck_IFTA_ID"];
Truck_HUT_ID = Request.Form["Truck_HUT_ID"];
Truck_Oregon_ID = Request.Form["Truck_Oregon_ID"];
Truck_New_Mexico_ID = Request.Form["Truck_New_Mexico_ID"];
Truck_Kentucky_ID = Request.Form["Truck_Kentucky_ID"];
Truck_Payment_Start_Date = Request.Form["Truck_Payment_Start_Date"];
Truck_Payment_Due_Date = Request.Form["Truck_Payment_Due_Date"];
Truck_Payment_Amount = Request.Form["Truck_Payment_Amount"];
Truck_Total_Payment = Request.Form["Truck_Total_Payment"];
Truck_Commission = Request.Form["Truck_Commission"];

var updateQueryString =@"UPDATE Trucks SET Truck_Number=@0,
Truck_Make=@1,
Truck_Model=@2,
Truck_Year=@3,
Truck_Vin=@8,
Truck_Empty_Weight=@5,
Truck_Assigned_To=@6,
Truck_Assigned_Date=@7,
Truck_Plate_Number=@8,
Truck_IFTA_ID=@9,
Truck_HUT_ID=@10,
Truck_Oregon_ID=@11,
Truck_New_Mexico_ID=@12,
Truck_Kentucky_ID=@13,
Truck_Payment_Start_Date=@14,
Truck_Payment_Due_Date=@15,
Truck_Payment_Amount=@16,
Truck_Total_Payment=@17,
Truck_Commission=@18 WHERE ID=@19";
db.Execute(updateQueryString,Truck_Number,Truck_Make,Truck_Model,Truck_Year,Truck_Vin,Truck_Empty_Weight,Truck_Assigned_To,Truck_Assigned_Date,Truck_Plate_Number,Truck_IFTA_ID,Truck_HUT_ID,Truck_Oregon_ID,Truck_New_Mexico_ID,Truck_Kentucky_ID,Truck_Payment_Start_Date,Truck_Payment_Due_Date,Truck_Payment_Amount,Truck_Total_Payment,Truck_Commission,ID);
 Response.Redirect("truck_list.cshtml");

Any help to figure out what is wrong I would appreciate it!

2
  • The parameterized query '(@0 nvarchar(3),@1 nvarchar(12),@2 nvarchar(8),@3 nvarchar(4),@4' expects the parameter '@8', which was not supplied. Commented May 13, 2016 at 19:23
  • Check to see if you actually have a form field with the name attribute of "Truck_Vin" Commented May 17, 2016 at 14:51

2 Answers 2

1

You have @8 listed twice, and you're missing @4.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I forgot to put it back, at first I thought it was meaning in the 4 spot it was supposed to be 8, so I changed 4 to 8, but forgot to put it back, but still get same error.
0

Truck_Vin=@8, should be Truck_Vin=@4,

4 Comments

Yes, I fixed that in my code, but still gives the same error, I thought that @4 was saying that should be @8 so I changed Truck_Vin=@4 to 8 just to check but forgot to put it back to 4 before posting here. Although it still is same error...
ok simple math: from @0 to @19 there are 20 variables Right? But are getting 19 values from Request.Form[] and , I think you should pass one more value in the db.Execute() method.
yes in that block there are 19 Request.Form[""] variables but there is 1 at the very top which is the var ID= Request["id"] variable which since this is an update query it pulls that one from the URL itself truck_edit.cshtml?id=2 scenario. Which is @19 on the list, and at the very end of the db.Execute(updateQueryString,,,,,,,,,,,,,,,,ID) setting...
I tried very hard to reproduce your issue, but no luck. In other posts with same problems solution is to check for null and if parameter is null, then pass DBNull.Value. I hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.