Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- //add SQL namespace
- using System.Data.SqlClient;
- namespace CRUD_Friday
- {
- public partial class add : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- //create connection string
- string myConnection = @"Data Source=JDTCAD2-22\SQLEXPRESS;Initial Catalog=cinemaDB;Integrated Security=True";
- //create new SQL connection
- SqlConnection con = new SqlConnection(myConnection);
- //open connection
- con.Open();
- //get VALUE from the webpage
- string getTitle = txtTitle.Text;
- decimal getRating = Convert.ToDecimal(txtRating.Text);
- //create SQL query
- string query = "INSERT INTO movie(title, rating) VALUES (@myTitle, @myRating)";
- //add data
- SqlCommand cmd = new SqlCommand(query, con);
- cmd.Parameters.AddWithValue("@myTitle", getTitle);
- cmd.Parameters.AddWithValue("@myRating", getRating);
- cmd.ExecuteNonQuery();
- //close connection
- con.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement