STORED PROCEDURE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Data.Sql;
using System.Collections.Specialized;
namespace WebApplication1
{
public partial class Registrationpage
: System.Web.UI.Page
{
SqlConnection
con = new SqlConnection("Data Source=siva-pc;Initial Catalog=master;Integrated
Security=True");
SqlCommand cmd = new
SqlCommand();
SqlDataAdapter da = new
SqlDataAdapter();
DataSet ds = new DataSet();
protected void
Page_Load(object sender, EventArgs e)
{
}
protected void
Button1_Click(object sender, EventArgs e)
{
con.Open();
//cmd.Connection = con;
SqlCommand cmd = new
SqlCommand("store",
con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@name",
TextBox1.Text);
cmd.Parameters.Add("@email",
TextBox2.Text);
cmd.Parameters.Add("@ph_no",
TextBox3.Text);
cmd.Parameters.Add("@place",
TextBox4.Text);
cmd.Parameters.Add("@qualification",
TextBox5.Text);
cmd.Parameters.Add("@occupation",
TextBox6.Text);
cmd.ExecuteNonQuery();
con.Close();
}
protected void
Button2_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand
cmd = new SqlCommand("select * from reg1", con);
cmd.ExecuteNonQuery();
SqlDataAdapter da=new
SqlDataAdapter(cmd);
DataSet ds=new DataSet();
da.Fill(ds);
GridView1.DataSource=ds;
GridView1.DataBind();
}
}
}
SQL STRORED PROCEDURE CREATING:
CREATE TABLE REG1
(
NAME VARCHAR(200) NOT NULL,
EMAIL TEXT NOT NULL,
PH_NO NUMERIC PRIMARY KEY,
PLACE VARCHAR(200),
QUALIFICATION TEXT,
OCCUPATION TEXT
)
SELECT * FROM REG1
create procedure STORE
(
@name varchar(200),
@email text ,
@ph_no numeric ,
@place varchar(200),
@qualification text,
@occupation text
)
as
begin
insert into REG1
(
NAME,
EMAIL,
PH_NO,
PLACE,
QUALIFICATION,
OCCUPATION
)
values
(
@name,
@email,
@ph_no,
@place,
@QUALIFICATION,
@occupation
)
end
No comments:
Post a Comment