Store procedure Data Base handling (procedure_insert).

 Ø Store procedure Data Base handling (procedure_insert).

1. Include procdure library (system.data).

2. Pass procedure name to sqlcommand parameters.

Syntax :- com= new sqlcommand(“procedure name”,connection object)

3. Set the command type (store procedure)

Syntax :-com.CommandType=commandtype.storeprocedure

 

 

STORE PROCEDURE

CREATE PROCEDURE PROCON (@ROLL1 AS  INT , @NAME1 AS VARCHAR(50))

 

AS 

 

BEGIN 

INSERT INTO DEMO (ROLL, NAME ) VALUES (@ROLL1, @NAME1)

 

 

END ;

 

 

 

 

 

 

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;

 

 

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

{

    SqlConnection con;

    SqlCommand com;

    SqlDataReader dr;

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

 

        }

 

    }

 

    protected void Button1_Click(object sender, EventArgs e)

    {

        //Data Source=LAPTOP-1B3T3LF5\SQLEXPRESS;Initial Catalog=college;Integrated Security=True

 

        string pth = @"Data Source=LAPTOP-1B3T3LF5\SQLEXPRESS;Initial Catalog=college;Integrated Security=True";

        con = new SqlConnection (pth);

        con.Open();

 

        com = new SqlCommand("PROCON", con);

        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.AddWithValue("ROLL1", TextBox1.Text);

        com.Parameters.AddWithValue("NAME1", TextBox2.Text);

 

        com.ExecuteNonQuery();

 

        Response.Write("RECORD SENT");

 

 

  }

}

 

Comments

Popular posts from this blog

ViewState for state management

Database joining