I have two form fields from which the user submits a "category" and an "element".
The following code inserts a category tone (I changed it from the embedded WebMatrix PDF file), but I have no idea how to insert an “element” into the “Items” table. I also need to add the id of the new category to the new row.
This is the code that still works.
@{ var db = Database.OpenFile("StarterSite.sdf");
var Category = Request["Category"];
var Item = Request["Item"];
if (IsPost) {
Category = Request["Category"];
if (Category.IsEmpty()) {
Validation.AddFieldError("Category", "Category is required");
}
Item = Request["Item"];
if (Item.IsEmpty()) {
Validation.AddFieldError("Item",
"Item type is required.");
}
if(Validation.Success) {
var insertQuery = "INSERT INTO Category (CategoryName) " +
"VALUES (@0)";
db.Execute(insertQuery, Category);
Response.Redirect(@Href("~/success"));
}
}
}
I guess / hope this is a very simple question to answer, so I hope no more details are required - but please let me know if there is any. Thank.