我有一张桌子,materials
和另一个,stock_refund
。我在单击一次按钮时执行这两个命令以同时更新两个表,但两个记录都进入同一个表。以下是我的代码:
SqlConnection con = new SqlConnection(@"Data Source=ANONYMOUS\SQLSERVER;Initial Catalog=IndoStar;Integrated Security=SSPI;");
con.Open();
SqlCommand cmd = new SqlCommand("Insert into stock_refund values('"+refund_stockname.Text + "','"+refund_sitename.Text + "','"+refund_day.Text + refund_month.Text + refund_year.Text + "','"+refund_quantity.Text + "','"+ refund_unit.Text+"')",con);
SqlCommand cmd1 = new SqlCommand("Insert into materials values('" + refund_stockname.Text + "','" + refund_day.Text + refund_month.Text + refund_year.Text + "','" + refund_quantity.Text + "','" + refund_unit.Text + "', 'refund','"+ refund_sitename.Text +"')", con);
int i = cmd.ExecuteNonQuery();
int j = cmd.ExecuteNonQuery();
if ((i > 0)&& (j>0))
{
MessageBox.Show("Stock refunded successfully","Information",MessageBoxButtons.OK,MessageBoxIcon.Information);
}