- Back to Home »
- ADO.NET , ASP.NET »
- ASP.NET C# code insert data using Stored Procedure
Posted by :
Sudhir Chekuri
Saturday, 5 October 2013
sql query creating store procedure
----------------
insert into tbl_null values(1,'ram')
select * from tbl_null
alter procedure sp_insertnull
@sno int,
@name varchar(20)
as begin
insert into tbl_null values(@sno,@name)
end
exec sp_insertnull 2,'hello'
-------------------
csharp code in asp.net
------------------
SqlConnection con = new SqlConnection("Data Source=SUDEER;Initial Catalog=college;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "sp_insertnull";
cmd.Parameters.Add("@sno", SqlDbType.Int).Value = TextBox1 .Text.Trim();
cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = TextBox2.Text.Trim();
cmd.Connection = con;
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
----------------
insert into tbl_null values(1,'ram')
select * from tbl_null
alter procedure sp_insertnull
@sno int,
@name varchar(20)
as begin
insert into tbl_null values(@sno,@name)
end
exec sp_insertnull 2,'hello'
-------------------
csharp code in asp.net
------------------
SqlConnection con = new SqlConnection("Data Source=SUDEER;Initial Catalog=college;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "sp_insertnull";
cmd.Parameters.Add("@sno", SqlDbType.Int).Value = TextBox1 .Text.Trim();
cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = TextBox2.Text.Trim();
cmd.Connection = con;
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();