com.ExecuteNonQuery()返回结果为-1
c#code
public static SqlConnection createCon()
{
con = new SqlConnection("server=ILSH0QYY4HVJMZX; database=db_WL;Integrated Security=True;");
return con;
}
public static bool execSQL(string sql)
{
SqlConnection con = createCon();
con.Open();
SqlCommand com = new SqlCommand(sql, con);
try
{
int i= com.ExecuteNonQuery();//执行update语句后i=-1
}
catch (Exception ex)
{
con.Close();
return false;
}
return true;
}
protected void gridviewGoodInfo_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
int ID =Convert.ToInt32(this.gridviewGoodInfo.DataKeys[e.NewSelectedIndex].Value.ToString());
string sql = string.Format("select Auditing from tb_Freight where ID={0}", ID);
SqlDataReader dr = DataOperate.getRow(sql);
dr.Read();
int Auditing=Convert.ToInt32(dr["Auditing"]);
if (Auditing == 0)
{
Auditing = 1;
}
else
{
Auditing = 0;
}
string updateSQL = string.Format("update tb_Freight set Auditing='{0}' where ID={1}",Convert.ToString(Auditing), ID);
DataOperate.execSQL(sql);
}