日期:2014-05-18 浏览次数:21548 次
public int ExecuteNonQuery(List<string> strSQL)
{
int index = 0;
CheckConnection();
//SqlCommand com = new SqlCommand(strSQL, con);
using (SqlCommand cmd = con.CreateCommand())
{
SqlTransaction tran = con.BeginTransaction();
cmd.Transaction = tran;
try
{
foreach (string item in strSQL)
{
cmd.CommandText = item;
cmd.ExecuteNonQuery();
}
tran.Commit();//如果都成功那么提交事物
}
catch (Exception ex)
{
index = -1;
//throw new Exception(ex.Message);
tran.Rollback();
}
//index = com.ExecuteNonQuery();
}
return index;
}
public void CheckConnection()
{
if (this.con.State == ConnectionState.Closed)
{
this.con.Open();
}
}
------解决方案--------------------
3楼说的对,没注意循环
------解决方案--------------------