Friday, August 4, 2023

Store Procedure Insert Update Delete Select

 

           Store Procedure Assignment

Stored Procedure For Find Button à

create procedure findProc(@name1 as varchar(50))

AS

BEGIN

select * From stud where name=@name1;

END;

 

Stored Procedure For Submit Button à

create procedure SubmitProc(@name1 as varchar(50),@email1 as varchar(50),@mobile1 as varchar(50),@photo1 as varchar(50), @pic1 as varchar(50))

AS

BEGIN

insert into stud values(@name1,@email1,@mobile1,@photo1,@pic1);

END;

 

Stored Procedure For Update Button  à

CREATE procedure updateProc(@name1 as varchar(50),@email1 as varchar(50))

AS

BEGIN

update stud set name =@name1 where email=@email1;

END;

Stored Procedure For Delete Button à

create procedure DeleteProc(@name1 as varchar(50))

AS

BEGIN

delete from stud where name=@name1

END;

 

StoredProcedureWeb.aspx file

 

 

 

StoredProcedureWeb.aspx.cs à

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;

 

namespace imageIntable

{

    public partial class StoredProcedureWeb : System.Web.UI.Page

    {

        SqlConnection con;

        SqlCommand cmd;

        SqlDataReader dr;

        protected void Page_Load(object sender, EventArgs e)

        {

            if (!IsPostBack)

            {

 

            }

        }

 

        protected void Button1_Click(object sender, EventArgs e)

        {

            string path = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True";

            con = new SqlConnection(path);

            con.Open();

 

            //string k = "insert into stud ";

 

            //connection procedure to c#

            cmd = new SqlCommand("SubmitProc", con);

 

            //using command type property

            cmd.CommandType = CommandType.StoredProcedure;

 

            //How to pass parameter

            cmd.Parameters.AddWithValue("name1",TextBox1.Text);

            cmd.Parameters.AddWithValue("email1",TextBox2.Text);

            cmd.Parameters.AddWithValue("mobile1",TextBox3.Text);

            cmd.Parameters.AddWithValue("photo1",Label1.Text);

            cmd.Parameters.AddWithValue("pic1",Label1.Text);

 

            cmd.ExecuteNonQuery();

            Response.Write("record saved");

        }

 

        protected void Button2_Click(object sender, EventArgs e)

        {

            string path = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True";

            con = new SqlConnection(path);

            con.Open();

 

            cmd = new SqlCommand("findProc", con);

 

            //using command type property

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("name1", TextBox1.Text);

            dr = cmd.ExecuteReader();

 

            GridView1.DataSource = dr;

            GridView1.DataBind();

            dr.Close();

 

        }

 

        protected void Button5_Click(object sender, EventArgs e)

        {

            string path = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True";

            con = new SqlConnection(path);

            con.Open();

 

            cmd = new SqlCommand("SelectAllProc", con);

 

 

            cmd.CommandType = CommandType.StoredProcedure;

            dr = cmd.ExecuteReader();

 

            GridView1.DataSource = dr;

            GridView1.DataBind();

            dr.Close();

 

        }

 

        protected void Button4_Click(object sender, EventArgs e)

        {

            string path = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True";

            con = new SqlConnection(path);

            con.Open();

            cmd = new SqlCommand("DeleteProc", con);

            cmd.Parameters.AddWithValue("name1", TextBox1.Text);

 

            cmd.CommandType = CommandType.StoredProcedure;

 

             cmd.ExecuteNonQuery();

 

            Response.Write("Record Deleted");

        }

 

        protected void Button3_Click(object sender, EventArgs e)

        {

                string path = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True";

            con = new SqlConnection(path);

            con.Open();

            cmd = new SqlCommand("updateProc", con);

            cmd.Parameters.AddWithValue("name1", TextBox1.Text);

            cmd.Parameters.AddWithValue("email1", TextBox2.Text);

 

            cmd.CommandType = CommandType.StoredProcedure;

 

            cmd.ExecuteNonQuery();

 

            Response.Write("Record Updated");

        }

     protected void Button6_Click(object sender, EventArgs e)

        {

            FileUpload1.SaveAs(Server.MapPath("~") + "//Images//" + FileUpload1.FileName);

 

            Label1.Text = FileUpload1.FileName;

 

        }

    }

}

OutPut Image à

No comments:

Post a Comment

GRIDVIEW ON ROW DATA BOUND EVENT

 Database Create  Student : roll , name , city , cost  Fix 6 Value  in Database Record  ====================================================...