How to make multiple tables update function in single button click.
Please help me sir.
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace cni
{
public partial class vw : System.Web.UI.Page
{
int empno = 0;
protected void Page_Load(object sender, EventArgs e)
{
empno = Convert.ToInt32(Request.QueryString["Id"].ToString());
Session["EmpId"] = empno;
String EmplooyeId = Session["emp_id"].ToString();
Label1.Text = " " + EmplooyeId + "";
String emp_nm = Session["emp_nm"].ToString();
Label2.Text = "" + emp_nm + " ";
String dept = Session["dept"].ToString();
Label3.Text = "" + dept + " ";
String designation_code = Session["designation_code"].ToString();
Label4.Text = "" + designation_code + " ";
String grd = Session["grd"].ToString();
Label5.Text = "" + grd + " ";
TextBox5.Text = "" + emp_nm + "," + EmplooyeId + "";
if (!IsPostBack)
{
BindTextBoxvalues();
}
}
private void BindTextBoxvalues()
{
string constr = ConfigurationManager.ConnectionStrings["IntranetConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand("select * from Mtrl_rcpt_rgster_cni_lab where Id=" + empno, con);
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
Label18.Text = dt.Rows[0][0].ToString();
Label6.Text = dt.Rows[0][2].ToString();
Label7.Text = dt.Rows[0][3].ToString();
Label8.Text = dt.Rows[0][4].ToString();
Label9.Text = dt.Rows[0][5].ToString();
Label10.Text = dt.Rows[0][8].ToString();
Label11.Text = dt.Rows[0][10].ToString();
Label12.Text = dt.Rows[0][11].ToString();
Label13.Text = dt.Rows[0][12].ToString();
Label14.Text = dt.Rows[0][13].ToString();
Label15.Text = dt.Rows[0][14].ToString();
Label16.Text = dt.Rows[0][15].ToString();
Label17.Text = dt.Rows[0][20].ToString();
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Response.Redirect("Indexnxtlng.aspx");
}
protected void DropDownList_Changed(object sender, EventArgs e)
{
if (DropDownList1.SelectedItem.Value == "Lab")
{
TextBox1.Visible = true;
Label19.Visible = true;
}
else
{
TextBox1.Visible = false;
Label19.Visible = false;
}
}
protected void btn_save_Click(object sender, EventArgs e)
{
string Issbmted = "YES";
string constr = ConfigurationManager.ConnectionStrings["IntranetConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("UPDATE Mtrl_rcpt_rgster_cni_lab SET lcn=@lcn,lcn_in_lb=@lcn_in_lb,dt_of_rcpt_in_lb = @dt_of_rcpt_in_lb,qunty=@qunty,dpstd_by=@dpstd_by,rcvd_by=@rcvd_by,rmk_two=@rmk_two,Issbmted=@Issbmted,emp_id_tw=@emp_id_tw WHERE Id = @Id"))
{
cmd.Parameters.AddWithValue("@Id", Label18.Text);
cmd.Parameters.AddWithValue("@Issbmted", Issbmted);
cmd.Parameters.AddWithValue("@lcn", DropDownList1.Text);
cmd.Parameters.AddWithValue("@lcn_in_lb", TextBox1.Text);
cmd.Parameters.AddWithValue("@dt_of_rcpt_in_lb", TextBox2.Text);
cmd.Parameters.AddWithValue("@qunty", TextBox3.Text);
cmd.Parameters.AddWithValue("@dpstd_by", TextBox4.Text);
cmd.Parameters.AddWithValue("@rcvd_by", TextBox5.Text);
cmd.Parameters.AddWithValue("@rmk_two", TextBox6.Text);
cmd.Parameters.AddWithValue("@emp_id_tw", Label1.Text);
con.Close();
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Label18.Text = "";
Label6.Text = "";
Label7.Text = "";
Label8.Text = "";
Label9.Text = "";
Label10.Text = "";
Label11.Text = "";
Label12.Text = "";
Label13.Text = "";
Label14.Text = "";
Label15.Text = "";
Label16.Text = "";
Label17.Text = "";
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
}
}
string Issbmted1 = "YES";
string constr1 = ConfigurationManager.ConnectionStrings["IntranetConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr1))
using (SqlCommand cmd1 = new SqlCommand("UPDATE mtrl_mstr SET Issbmted1=@Issbmted1 WHERE Mtrl_cd = @Mtrl_cd"))
{
cmd1.Parameters.AddWithValue("@Mtrl_cd", Label6.Text);
cmd1.Parameters.AddWithValue("@Issbmted1", Issbmted1);
con.Close();
cmd1.Connection = con;
con.Open();
cmd1.ExecuteNonQuery();
con.Close();
}
}
protected void btn_cancel_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
}
}
}
CREATE TABLE [dbo].[mtrl_mstr] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Mtrl_cd] NCHAR (50) NULL,
[Mtrl_dscrptn] NCHAR (500) NULL,
[Issbmted1] VARCHAR (3) DEFAULT ('NO') NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
CREATE TABLE [dbo].[Mtrl_rcpt_rgster_cni_lab] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[emp_id] VARCHAR (500) NULL,
[Mtrl_cd] VARCHAR (500) NULL,
[dsc] VARCHAR (500) DEFAULT ('na') NULL,
[area] VARCHAR (10) DEFAULT ('na') NULL,
[mtrl_typ ] VARCHAR (100) DEFAULT ('na') NULL,
[lcn] VARCHAR (500) DEFAULT ('na') NULL,
[lcn_in_lb] VARCHAR (500) DEFAULT ('na') NULL,
[typ_of_prcrmnt_in_cs_of_deptt_prchs] VARCHAR (500) DEFAULT ('na') NULL,
[quntty_req] VARCHAR (500) DEFAULT ('na') NULL,
[dprtmntl_rg_s_no_page_n] VARCHAR (500) DEFAULT ('na') NULL,
[vndr_nm] VARCHAR (500) DEFAULT ('na') NULL,
[Vndr_mob_no] VARCHAR (500) DEFAULT ('na') NULL,
[amt] VARCHAR (500) DEFAULT ('na') NULL,
[purchs_by] VARCHAR (500) DEFAULT ('na') NULL,
[dt_of_prchs] VARCHAR (50) DEFAULT ('na') NULL,
[dt_of_rcpt_in_lb] VARCHAR (50) DEFAULT ('na') NULL,
[qunty] VARCHAR (50) DEFAULT ('na') NULL,
[dpstd_by] VARCHAR (500) DEFAULT ('na') NULL,
[rcvd_by] VARCHAR (500) DEFAULT ('na') NULL,
[rmk_one] VARCHAR (500) DEFAULT ('na') NULL,
[siv] VARCHAR (500) DEFAULT ('na') NULL,
[rmk_two] VARCHAR (500) DEFAULT ('na') NULL,
[Issbmted] VARCHAR (3) DEFAULT ('NO') NULL,
[Issend] VARCHAR (3) DEFAULT ('NO') NULL,
[emp_id_tw] VARCHAR (500) DEFAULT ('na') NULL,
[DATE] DATE DEFAULT (getdate()) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);