I am struggling with a simple add data form and getting error
Parameterized query expects a parameter value which was not supplied.
Parameter name: 1
Line 55: var sqlCommand = "INSERT INTO GiftAid (Email, Title, FirstName, LastName, Address1, Address2, City, County, Postcode, GiftAidDate) VALUES(@0, @1, @2, @3, @4, @5, @6, @7, @8, @9)";
Line 56: db.Execute(sqlCommand, email, title, firstname, lastname, address1, address2, city, county, postcode, giftaiddate);
Line 57: Response.Redirect("~/");
Here is my code
var email = Request.Form["formEmail"];
var title = Request.Form["formTitle"];
var firstname = Request.Form["formFirstName"];
var lastname = Request.Form["formLastName"];
var address1 = Request.Form["formAddress1"];
var address2 = Request.Form["formAddress2"];
var city = Request.Form["formCity"];
var county = Request.Form["formCounty"];
var postcode = Request.Form["formPostcode"];
var giftaiddate = Request.Form["formGiftAidDate"];
var db = Database.Open("Donations");
var sqlCommand = "INSERT INTO GiftAid (Email, Title, FirstName, LastName, Address1, Address2, City, County, Postcode, GiftAidDate) VALUES(@0, @1, @2, @3, @4, @5, @6, @7, @8, @9)";
db.Execute(sqlCommand, email, title, firstname, lastname, address1, address2, city, county, postcode, giftaiddate);
Response.Redirect("~/");
I think it refers to Title field, I have declared var and got form elements correctly named and I have a table GiftAid with all the fields. Ashamed to say that I am unable to resolve this error. Have spent whole day over it, consulted books by Mike & Imar,
Laurence, Jim Wang
Try to only give db.execute(sqlcommand) & try. I am not sure why you need to pass the value again since you have already passed it in your declaration command. Maybe this is causing an issue. Please check
Please mark as answered if this answer helped you.
But I removed var title and form elements - no error, put them back - again error, I did it few times in desperation and then it worked. I examined the code closely, it is just the same as above but it is working now.
Not sure why it was not working before.
Many thanks for your interest and prompt reply
Hamid
Marked as answer by Dino He - MSFT on Mar 30, 2012 02:47 AM
SHR
Member
30 Points
65 Posts
Struggling with parameterized query
Mar 25, 2012 12:20 PM|LINK
Hi knowledgeable people
I am struggling with a simple add data form and getting error
Parameterized query expects a parameter value which was not supplied.
Parameter name: 1
Line 55: var sqlCommand = "INSERT INTO GiftAid (Email, Title, FirstName, LastName, Address1, Address2, City, County, Postcode, GiftAidDate) VALUES(@0, @1, @2, @3, @4, @5, @6, @7, @8, @9)"; Line 56: db.Execute(sqlCommand, email, title, firstname, lastname, address1, address2, city, county, postcode, giftaiddate);Line 57: Response.Redirect("~/");var email = Request.Form["formEmail"];
var title = Request.Form["formTitle"];
var firstname = Request.Form["formFirstName"];
var lastname = Request.Form["formLastName"];
var address1 = Request.Form["formAddress1"];
var address2 = Request.Form["formAddress2"];
var city = Request.Form["formCity"];
var county = Request.Form["formCounty"];
var postcode = Request.Form["formPostcode"];
var giftaiddate = Request.Form["formGiftAidDate"];
var db = Database.Open("Donations");
var sqlCommand = "INSERT INTO GiftAid (Email, Title, FirstName, LastName, Address1, Address2, City, County, Postcode, GiftAidDate) VALUES(@0, @1, @2, @3, @4, @5, @6, @7, @8, @9)";
db.Execute(sqlCommand, email, title, firstname, lastname, address1, address2, city, county, postcode, giftaiddate);
Response.Redirect("~/");
<form method="post" action="">
<label class="labelleft">* Email:</label>
<input type="text" name="formEmail" class="textbox" /> <br/>
<label class="labelleft">Title:</label>
<input type="text" name="formTitle" class="textbox" /> <br/>
<label class="labelleft">* First Name:</label>
<input type="text" name="formFirstName" class="textbox" /> <br/>
...
I think it refers to Title field, I have declared var and got form elements correctly named and I have a table GiftAid with all the fields. Ashamed to say that I am unable to resolve this error. Have spent whole day over it, consulted books by Mike & Imar, Laurence, Jim Wang
Any help is greatly appreciated.
Thanks
Hamid
Shankar_ss
Participant
1270 Points
279 Posts
Re: Struggling with parameterized query
Mar 25, 2012 12:32 PM|LINK
Try to only give db.execute(sqlcommand) & try. I am not sure why you need to pass the value again since you have already passed it in your declaration command. Maybe this is causing an issue. Please check
Shankar
SHR
Member
30 Points
65 Posts
Re: Struggling with parameterized query
Mar 25, 2012 01:57 PM|LINK
Thank you Shankar
I got the error again
But I removed var title and form elements - no error, put them back - again error, I did it few times in desperation and then it worked. I examined the code closely, it is just the same as above but it is working now.
Not sure why it was not working before.
Many thanks for your interest and prompt reply
Hamid