Stored Procedure
Access Stored Procedure Using C#
CREATE PROCEDURE dbo.Insert_Table1 /* Procedure Name dbo.Insert_Table1 */(@id numeric(18,0), /* Input Parameter */@name varchar(50) /* Input Parameter */)ASinsert into Table1values (@id ,@name)return
Access Stored Procedure Using C#
private void btnInsert_Click(object sender, EventArgs e){SqlConnection cnn = new SqlConnection();cnn.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True";cnn.Open();System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();cmd.Connection = cnn;cmd.CommandType = CommandType.StoredProcedure;cmd.Parameters.AddWithValue("id",Convert.ToInt32(textBox1.Text));cmd.Parameters.AddWithValue("name", textBox2.Text);cmd.CommandText = "Insert_Table1";cmd.ExecuteNonQuery();MessageBox.Show("Data inserted Successfully");}
- Stored procedure 80% faster compare to SQL QUERY.
- Stored procedure reducing work load.
- Stored procedure stored in database as object.
- Stored procedure also return a value.