使用 INSERT INTO ... SELECT 将一个 table 的值添加到另一个
Adding values of one table into another with INSERT INTO ... SELECT
我需要在 visual studio 2008 中使用 c# 从 transac(acnum,scriptname,Quantity,Price)
向 table sales(acnum,scriptname,shares_bought)
添加值。我正在使用下面显示的代码,但它没有插入价值进入销售数据库。
它没有显示任何错误或异常,但它也没有更新 sales
table。
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection Con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
Con.Open();
string insertsale = "INSERT INTO sales(acnum, scriptname, shares_bought) select acnum,scriptname,Quantity from transac";
SqlCommand cmd = new SqlCommand(insertsale, Con);
cmd.ExecuteNonQuery();
Con.Close();
}
catch (Exception ex)
{
Response.Write("error" + ex.ToString());
}
}
问题是我对按钮点击使用了 PostUrl。 .所以我认为它是在不处理代码的情况下重定向到下一页。现在已修复。
我需要在 visual studio 2008 中使用 c# 从 transac(acnum,scriptname,Quantity,Price)
向 table sales(acnum,scriptname,shares_bought)
添加值。我正在使用下面显示的代码,但它没有插入价值进入销售数据库。
它没有显示任何错误或异常,但它也没有更新 sales
table。
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection Con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
Con.Open();
string insertsale = "INSERT INTO sales(acnum, scriptname, shares_bought) select acnum,scriptname,Quantity from transac";
SqlCommand cmd = new SqlCommand(insertsale, Con);
cmd.ExecuteNonQuery();
Con.Close();
}
catch (Exception ex)
{
Response.Write("error" + ex.ToString());
}
}
问题是我对按钮点击使用了 PostUrl。 .所以我认为它是在不处理代码的情况下重定向到下一页。现在已修复。