拼好的SQL string,怎么样去执行省事了..ADO.NET感觉挺费事的..
我的sql问是从数据库中取出来的...然后通过处理得到正确的SQL文.恰好2个SQL文都是访问的同一数据库........求个省事,简洁的思路啊...............
------解决方案--------------------字打对,问题描述清楚,看着有点晕。
------解决方案-------------------- public void ExecuteSqlNonQueryTrans(string[] strSQL, IList<IList<SqlParameter>> paramLists)
{
SqlConnection conn = new SqlConnection(strconnect);
conn.Open();
SqlTransaction tran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = tran;
cmd.Connection = conn;
try
{
for(int i=0;i<strSQL.Length;i++)
{
cmd.CommandText = strSQL[i];
if (paramLists[i] != null)
{
cmd = AddCommandParam(cmd, paramLists[i]);
}
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
}
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
throw e;
}
finally
{
conn.Close();
}
}
<