Guest User

Untitled

a guest
Apr 26th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. //add the new recipie to the database
  2. protected void Button1_Click(object sender, EventArgs e)
  3. {
  4. string recipie_name = TextBox_RecipeName.Text;
  5. string recipie_instruction = TextBox_RecipeInstructions.Text;
  6. int recipie_category_id = DropDownCategory.SelectedValue;
  7.  
  8. try
  9. {
  10. Database db = DatabaseFactory.CreateDatabase("App_Con_str");
  11. string SQLAddRecipie = "INSERT INTO recipies VALUES(@name, @instructions, @category_id)";
  12. DbCommand dbCommand = db.GetSqlStringCommand(SQLAddRecipie);
  13.  
  14. db.AddInParameter(dbCommand, "name", DbType.String, recipie_name);
  15. db.AddInParameter(dbCommand, "instructions", DbType.String, recipie_instruction);
  16. db.AddInParameter(dbCommand, "category_id", DbType.String, recipie_category_id);
  17.  
  18. db.ExecuteNonQuery(dbCommand);
  19. Response.Write("Your recipie has been added");
  20.  
  21. }
  22. catch (DbException)
  23. {
  24. throw;
  25. }
  26. }
Add Comment
Please, Sign In to add comment