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);

你可能感兴趣的:(help)