SQLhelper使用事务和参数

事务:
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);
posted @ 2009-09-01 14:42  与时俱进  阅读(913)  评论(0编辑  收藏  举报
友情链接:同里老宅院民居客栈