using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using MyConfig;
namespace WebApplication12
{
/// <summary>
/// WebForm2 的摘要描述。
/// </summary>
public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox0;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Btnsave;
private void Page_Load(object sender, System.EventArgs e)
{
// 在這裡放置使用者程式碼以初始化網頁
}
#region Web Form 設計工具產生的程式碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 此為 ASP.NET Web Form 設計工具所需的呼叫。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 此為設計工具支援所必須的方法 - 請勿使用程式碼編輯器修改
/// 這個方法的內容。
/// </summary>
private void InitializeComponent()
{
this.Btnsave.Click += new System.EventHandler(this.Btnsave_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Btnsave_Click(object sender, System.EventArgs e)
{
string SQL = "insert into [1.1] (a,b)values('1','1111')";
string constr = MyConfig.MyConfigSectionHandler.ConnectionString;
SqlConnection myconn = new SqlConnection(constr);
myconn.Open();
System.Data.SqlClient.SqlTransaction tran = myconn.BeginTransaction();
try
{
SqlHelper.ExecuteNonQuery(tran,CommandType.Text,SQL);
for(int i = 0;i<2;i++)
{
TextBox txt = (TextBox)Page.FindControl("TextBox"+i);
string SQL2 = " insert into [2.1] (a,c)values('2','"+txt.Text+"')";
try
{
SqlHelper.ExecuteNonQuery(tran,CommandType.Text,SQL2);
tran.Commit();
}
catch
{
tran.Rollback();
}
}
tran.Commit();
}
catch(Exception error)
{
string a = error.Message;
tran.Rollback();
}
finally
{
tran.Dispose();
myconn.Close();
}
}
}
}