protected void Button1_Click(object sender, EventArgs e)
{
/*=============测试通过===============*/
OleDbConnection con = new
OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data
Source=C:/Inetpub/wwwroot/DotNetArticle/App_Data/DotNetArticle.mdb");
con.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = con;
cmd.Transaction = con.BeginTransaction();
try
{
string sql1 = "insert into teaminfo (num,username,isplay) values(1,'a',1)";
string sql2 = "insert into teaminfo (num,username,isplay) values(2,'b',1)";
string sql3 = "insert into teaminfo (num,username,isplay) values(3,'c',1)";
cmd.Connection = con;
cmd.Transaction = con.BeginTransaction();
try
{
string sql1 = "insert into teaminfo (num,username,isplay) values(1,'a',1)";
string sql2 = "insert into teaminfo (num,username,isplay) values(2,'b',1)";
string sql3 = "insert into teaminfo (num,username,isplay) values(3,'c',1)";
string[] SQLStringList = { sql1, sql2, sql3 };
for (int n = 0; n < SQLStringList.Length; n++)
{
string strsql = SQLStringList[n].ToString();
if (strsql.Trim().Length > 1)
{
cmd.CommandText = strsql;
cmd.ExecuteNonQuery();
}
}
cmd.Transaction.Commit(); //提交事务
Response.Write("OK");
for (int n = 0; n < SQLStringList.Length; n++)
{
string strsql = SQLStringList[n].ToString();
if (strsql.Trim().Length > 1)
{
cmd.CommandText = strsql;
cmd.ExecuteNonQuery();
}
}
cmd.Transaction.Commit(); //提交事务
Response.Write("OK");
}
catch (Exception)
{
cmd.Transaction.Rollback();
}
finally
{
con.Close();
}
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 你所不知道的 C/C++ 宏知识
· 聊一聊 操作系统蓝屏 c0000102 的故障分析
· SQL Server 内存占用高分析
· .NET Core GC计划阶段(plan_phase)底层原理浅谈
· .NET开发智能桌面机器人:用.NET IoT库编写驱动控制两个屏幕
· 我干了两个月的大项目,开源了!
· 推荐一款非常好用的在线 SSH 管理工具
· 千万级的大表,如何做性能调优?
· 盘点!HelloGitHub 年度热门开源项目
· Phi小模型开发教程:用C#开发本地部署AI聊天工具,只需CPU,不需要GPU,3G内存就可以运行,