c#为什么 sql语句sqlstr会运行两次 sqlstr2都没问题
string connstr = "server=.;database=library;uid=sa;pwd=foolish;";
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
string sqlstr = "update book set 图书数量=图书数量-" + Convert.ToInt32(textBox5.Text) + "where 图书编号=" + textBox4.Text;
SqlCommand comm = new SqlCommand(sqlstr, conn);
comm.Connection = conn;
comm.ExecuteNonQuery();
if (comm.ExecuteNonQuery() > 0 )
{
string sqlstr2 = "insert into book2(被借阅图书编号,借阅数量) values(" + textBox4.Text + "," + Convert.ToInt32(textBox5.Text) + ")";
SqlCommand comm2 = new SqlCommand(sqlstr2, conn);
comm2.Connection = conn;
comm2.ExecuteNonQuery();
MessageBox.Show("借阅成功");
}
conn.Close();
------解决方案--------------------
comm.ExecuteNonQuery();
if (comm.ExecuteNonQuery() > 0 )
{
看你上面代码,执行两次ExecuteNonQuery
------解决方案--------------------
------解决方案--------------------