hi...Its very easy.. just take a look at the following Program.
e.g. StudentMaster
Id_int,sName_vcr,Roll_No_int
1 Sumit 100
CREATE Procedure AddUpdateGetStudent
(
@para_vcr VARCHAR(20)='',
@Id_int INT=0,
@sName_vcr VARCHAR='',
@Roll_No_int INT=0
)
AS
BEGIN
IF @para_vcr='Get'
BEGIN
SELECT * FROM StudentMaster
END
ELSE IF @para_vcr='ADD'
BEGIN
INSERT INTO StudentMaster
(Id_int,sName_vcr,Roll_No_int)
VALUES
(@Id_int,@sName_vcr,@Roll_No_int )
END
ELSE IF @para_vcr='UPADTE'
BEGIN
UPDATE Student_Master
SET
sName_vcr=@sName_vcr,
Roll_No_int=@Roll_No_int
WHERE Id_int=@Id_int
END
ELSE IF @para_vcr='Delete'
BEGIN
DELETE FROM StudentMaster
WHERE Id_int=@Id_int
END
END
Now In C#
add following namespaces in your Page
using System.Data;
using System.Data.SqlClient;
class ABC
{
SQLConnection con=new SqlConnection("Data Source=.SQLEXPRESS;DataBase=TEST_DB;Integrated Security=true");
private void btnAdd_Click(object sender,EventArgs e)
{
using(SqlCommand cmd=new SqlCommand("AddUpdateStudentMaster",con))
{
cmd.CommandType=CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@para_vcr","Add");
cmd.Parameters.AddWithValue("@Id_int",int.parse(txtId.Text));
cmd.Parameters.AddWithValue("@sName_vcr",txtName.Text); cmd.Parameters.AddWithValue("@Roll_No_int",int.parse(txtRollNo.Text));
con.Open();
cmd.ExecuteNonQuery();
con.close();
Response.Write("Record Added Successfully.");
}
}
private void btnAdd_Click(object sender,EventArgs e)
{
using(SqlCommand cmd=new SqlCommand("AddUpdateStudentMaster",con))
{
cmd.CommandType=CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@para_vcr","Update");
cmd.Parameters.AddWithValue("@Id_int",int.parse(txtId.Text));
cmd.Parameters.AddWithValue("@sName_vcr",txtName.Text); cmd.Parameters.AddWithValue("@Roll_No_int",int.parse(txtRollNo.Text));
con.Open();
cmd.ExecuteNonQuery();
con.close();
Response.Write("Record Updated Successfully.");
}
}
}
In this way u can use many conditions as per your requirement.
hope u got it...
have a nice day.