Hi,
Check like this .I have made a simple workout for you.
create common function and pass your SP Statement type .
using System.Data;
using System.Data.SqlClient;
private void btnInsert_Click(object sender, EventArgs e)
{
Execute_SQLSP("Insert");
}
private void btnUpdate_Click(object sender, EventArgs e)
{
Execute_SQLSP("Update");
}
private void btnDelete_Click(object sender, EventArgs e)
{
Execute_SQLSP("Select");
}
/Function to Execute Sp from your c# Code.
public void Execute_SQLSP(String SP_statementType)
{
try
{
SqlConnection myConnection = new SqlConnection(dbConnectionString);
SqlCommand("MasterInsertUpdateDelete", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add(new SqlParameter("@sno ", SqlDbType.Int)).Value = yourIntegersno;
myCommand.Parameters.Add(new SqlParameter("@name ", SqlDbType.VarChar)).Value = "YOUR_NAME";
myCommand.Parameters.Add(new SqlParameter("@phone ", SqlDbType.BigInt)).Value = yourphone;
myCommand.Parameters.Add(new SqlParameter("@city ", SqlDbType.VarChar)).Value = "YOUR_city ";
myCommand.Parameters.Add(new SqlParameter("@statementType ", SqlDbType.NVarChar)).Value = SP_statementType;
myConnection.Open();
myCommand.ExecuteNonQuery();
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter();
mySqlDataAdapter.SelectCommand = myCommand;
DataSet yourDataSet = new DataSet();
mySqlDataAdapter.Fill(yourDataSet);
myConnection.Close();
}
catch (SqlException ex)
{
}
}