日期:2014-05-18 浏览次数:20491 次
SqlConnection conn = new SqlConnection(STR_CONN); SqlCommand cmd = new SqlCommand(); cmd.CommandTimeout = timeOut; cmd.Connection = conn; try { conn.Open(); cmd.Transaction = conn.BeginTransaction(); } catch { conn.Close(); return false; } try { foreach(string str in sql) { if(str != null) { if(str.Trim() != "") { cmd.CommandText = str; cmd.ExecuteNonQuery(); } } } cmd.Transaction.Commit(); conn.Close(); return true; } catch { cmd.Transaction.Rollback(); conn.Close(); return false; }
------解决方案--------------------
提供参考
http://www.ebookit.cn/254.html