事务:
string myConnectString = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30";
SqlConnection myConnection = new SqlConnection(myConnectString);
myConnection.Open();
SqlTransaction st = myConnection .BeginTransaction();
try
{
...
SqlHelper.ExecuteDataset(st,...);
SqlHelper.ExecuteDataset(st,...);
...
st.Commit();
}
catch(SqlException ee)
{
st.Rollback();
throw ee;
}
参数:
SqlParameter[] paramColl = new SqlParameter[2];
SqlParameter param = new SqlParameter("@title",SqlDbType.NVarChar,40);
param.Value = txt_title.Text;
paramColl[0] = param;
param = new SqlParameter("@content",SqlDbType.Text);
param.Value = content.Value;
paramColl[1] = param;
string sqlStr = "p_insertNews";
DBhelper.ExecuteProcedure(connStr, sqlStr, paramColl);
SQLhelper使用事务和参数
最新推荐文章于 2021-09-14 08:56:16 发布