我在SQL中有两个表。我需要将数据从一个表插入到另一个表。我已经成功完成了,但是问题是我需要从文本框中额外添加一个列值。我将显示我的代码
protected void Button2_Click1(object sender, EventArgs e)
{
String str1 = "insert into table2(Code,Qty,UPrice,Total) select Code,Qty,UPrice,Total from table1 ;";
SqlCommand cmd = new SqlCommand(str1, con);
con.Open();
SqlDataAdapter da1 = new SqlDataAdapter();
cmd.Parameters.AddWithValue("@Num", TextBox1.Text);
da1.SelectCommand = cmd;
DataSet ds1 = new DataSet();
da1.Fill(ds1, "Code");
GridView1.DataSource = ds1;
con.Close();
}
在这里,我需要将Num添加到不在table1中的table2中。所以我需要从textbox1添加它。如何将Num值添加到文本框中的所有数据中。
protected void Button2_Click1(object sender, EventArgs e)
{
String str1 = "insert into table2(Code,Qty,UPrice,Total,Num) select Code,Qty,UPrice,Total,'"+TextBox1.Text+"' from table1 ;";
SqlCommand cmd = new SqlCommand(str1, con);
con.Open();
SqlDataAdapter da1 = new SqlDataAdapter();
da1.SelectCommand = cmd;
DataSet ds1 = new DataSet();
da1.Fill(ds1);
GridView1.DataSource = ds1;
con.Close();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句