Saturday, March 5, 2011

Stored Procedure In

1.Add using Syste.Data.SqlClient namespace.

2.Create a connection string for that.
Right click on your database(in server emplorer) and properties.
Copy the connection string property of database.

3.In your code right SqlConnection con=new SqlConnection(@"copy connection string here");

4.Now create a command
SqlCommand cmd=new ("StoredProcedureName",con);

5.Set commandtype of cmd

6.Add the parameter one by one
For example My stored procedure accepts two parameter name and address then pass as follows:
cmd.Parameters.add(new parameters("@name",SqlDbType.Varchar,size).value=textbox1.text;
cmd.Parameters.add(new parameters("@address",SqlDbType.Varchar,size).value=textbox2.text;

6.Now Open the connection by con.Open();

7.Execute the command by cmd.ExecuteNonQuery();

8.Close the connection by con.close();