hi, i have done this done in 3-tier architecture. i have used 2 different store procedure for insert data in two different table.
On save_button click i have passed parameters for that 2 different stored procedure prom .cs page to BAL Class by creating BAL's object.
And from BAL to DAL class.In DAL Class i have created 2 different functions for that two different stored procedure.
Refer This Code --
In .CS Page:-
protected void Button1_Click(object sender, EventArgs e)
{
name = Txt1.Text;
pname = Txt5.Text;
pcode = Txt3.Text;
addr = Txt4.Text;
pc = Txt3.Text;
rmname=box1.Text;
rmbatchno = box2.Text;
mfg_date = dt.Date;
pBAL.insert(name, pname, pcode, addr);
pBAL.insert2(pc, rmname, rmbatchno, mfg_date);
}
In BAL:-
public void insert(string name, string pname, string pcode, string addr)
{
pDAL.insert(name, pname, pcode, addr);
}
public void insert2(string prcode, string rmname, string rmbatchno, DateTime mfg_date)
{
pDAL.insert2(prcode,rmname,rmbatchno,mfg_date);
}
In DAL:-
public void insert(string name, string pname, string pcode, string addr)
{
SqlCommand sqlcmd = new SqlCommand("pfirst", con);
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.Add("@u", SqlDbType.VarChar).Value = name;
sqlcmd.Parameters.Add("@n", SqlDbType.VarChar).Value = pname;
sqlcmd.Parameters.Add("@a", SqlDbType.VarChar).Value = pcode;
sqlcmd.Parameters.Add("@c", SqlDbType.VarChar).Value = addr;
con.Open();
sqlcmd.ExecuteNonQuery();
con.Close();
}
public void insert2(string prcode ,string rmname, string rmbatchno,DateTime mfg_date)
{
SqlCommand sqlcmd1 = new SqlCommand("psecond", con);
sqlcmd1.CommandType = CommandType.StoredProcedure;
con.Open();
sqlcmd1.Parameters.Add("@u", SqlDbType.VarChar).Value = prcode;
sqlcmd1.Parameters.Add("@n", SqlDbType.VarChar).Value = rmname;
sqlcmd1.Parameters.Add("@a", SqlDbType.VarChar).Value = rmbatchno;
sqlcmd1.Parameters.Add("@c", SqlDbType.DateTime).Value = mfg_date;
sqlcmd1.ExecuteNonQuery();
con.Close();
}