how to remove error from the VALUE (@0,@1,@2) fields ?? everytime i write something it runs fine..bt when i add this one it gives error..bt this time a new one..it showed that page has been removed O.o
i mean how ?? the page has been removed ?? when i did nthng..any suggestions ?? here is the code :
C#
@{
Validation.RequireField("Name", "Product name is required.");
Validation.RequireField("Description", "Product description is required.");
Validation.RequireField("Price", "Product price is required.");
var db = Database.Open("SmallBakery");
var Name = Request.Form["Name"];
var Description = Request.Form["Description"];
var Price = Request.Form["Price"];
if (IsPost && Validation.IsValid()) {
// Define the insert query. The values to assign to the
// columns in the Product table are defined as parameters
// with the VALUES keyword.
if(ModelState.IsValid) {
var insertQuery = "INSERT INTO Product (Name, Description, Price) " +
"VALUES (@0, @1, @2)";
db.Execute(insertQuery, Name, Description, Price);
// Display the page that lists products.
Response.Redirect("~/ListProducts");
}
}
}
valueDatabasecsharp
Please "Marks As Answer" if any answer helped you out!
~~! FIREWALL !~~
Afzaal.Ahmad...
Contributor
2662 Points
1040 Posts
Validation
Aug 16, 2012 03:23 PM|LINK
how to remove error from the VALUE (@0,@1,@2) fields ?? everytime i write something it runs fine..bt when i add this one it gives error..bt this time a new one..it showed that page has been removed O.o
i mean how ?? the page has been removed ?? when i did nthng..any suggestions ?? here is the code :
C#
@{ Validation.RequireField("Name", "Product name is required."); Validation.RequireField("Description", "Product description is required."); Validation.RequireField("Price", "Product price is required."); var db = Database.Open("SmallBakery"); var Name = Request.Form["Name"]; var Description = Request.Form["Description"]; var Price = Request.Form["Price"]; if (IsPost && Validation.IsValid()) { // Define the insert query. The values to assign to the // columns in the Product table are defined as parameters // with the VALUES keyword. if(ModelState.IsValid) { var insertQuery = "INSERT INTO Product (Name, Description, Price) " + "VALUES (@0, @1, @2)"; db.Execute(insertQuery, Name, Description, Price); // Display the page that lists products. Response.Redirect("~/ListProducts"); } } }value Database csharp
~~! FIREWALL !~~
JTS-V
Member
29 Points
19 Posts
Re: Validation
Aug 19, 2012 05:14 PM|LINK
What does this code have to do with that error message?
Is the code actually inserting anything into the database? Can you please post the actual error?
Please "Mark As Answer" if the post helped you.
Afzaal.Ahmad...
Contributor
2662 Points
1040 Posts
Re: Validation
Aug 19, 2012 05:44 PM|LINK
Sorry about the problem brother. But I had this issue solved but forgot to show this thread as Solved.
So the issue was that I used this syntax var insertQuery = INSERT INTO Product (Name, Description, Price) Value ( @0, @1, @2)
But I had to use this one : var insertQuery = "INSERT INTO Product (Name, Description, Price) Value ( @0, @1, @2)"
The error was due to the quotation. Nothing else!
~~! FIREWALL !~~
JTS-V
Member
29 Points
19 Posts
Re: Validation
Aug 19, 2012 05:53 PM|LINK
No worries, glad everything worked out.
Please "Mark As Answer" if the post helped you.