示例代碼:
SqlServerDataBase obj = new SqlServerDataBase();
SqlConnection conn = obj.DBconn();
conn.Open();
SqlTransaction myTrans;
myTrans = conn.BeginTransaction(IsolationLevel.ReadCommitted);
try
{
obj.Insert("insert into StuInfo (StuNumber,Name,Sex,Specialty) values('" + stuNumber + "','" + name + "','" + sex + "','" + specialty + "')", null);
obj.Insert("insert into StuSkill(StuNumber,Skill) values('" + stuNumber + "','" + skill + "')", null);
myTrans.Commit();
Response.Write("兩條數據均插入到數據庫中!");
}
catch (Exception ex)
{
try
{
myTrans.Rollback();
}
catch (SqlException sqlEx)
{
if (obj.DBconn() != null)
{
Response.Write(sqlEx.GetType(