|
|
|
รบกวนพี่ๆ ช่วยแนะนำแนวทางให้ผมหน่อยน่ะครับ ว่ามันเกิดจากข้อผิดพลาดอะไร |
|
|
|
|
|
|
|
ผมไม่รู้ว่ามันเกิดขึ้นเพราะอะไร
Code (C#)
try
{
string strcon = "Provider = Microsoft.Jet.OleDb.4.0;" +
"Data Source = D:/Project/WindowsFormsApplication1/WindowsFormsApplication1/database/project.mdb";
OleDbConnection conn = new OleDbConnection(strcon);
string sql = "INSERT INTO login(email,username,password,yourname,mobile)" +
"VALUES('"+this.txtemail.Text+ "','" + this.txtusername.Text + "','" + this.txtrepassword.Text + "','" + this.txtname.Text + "','" + this.txtmobile.Text + "') ";
OleDbCommand cmd = new OleDbCommand(sql, conn);
OleDbTransaction trans;
try
{
conn.Open();
trans = conn.BeginTransaction();
cmd.Connection = conn;
cmd.CommandText = sql;
cmd.Transaction = trans;
cmd.ExecuteNonQuery();
if (MessageBox.Show("ข้อมูลถุกต้องหรือไม่?", "Confirm", MessageBoxButtons.OKCancel) == DialogResult.OK)
trans.Commit();
else
trans.Rollback();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
Tag : .NET, Ms Access, C#
|
|
|
|
|
|
Date :
2015-09-19 21:32:31 |
By :
illmndraft |
View :
798 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมว่าคุณใช้ Transaction ผิดครับ ลองไล่ดู Step ครับ
Code (C#)
System.Data.OleDb.OleDbConnection objConn;
System.Data.OleDb.OleDbCommand objCmd;
String strConnString, strSQL;
OleDbTransaction Trans;
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
Server.MapPath("database/mydatabase.mdb") + ";Jet OLEDB:Database Password=;";
objConn = new System.Data.OleDb.OleDbConnection(strConnString);
objConn.Open();
//*** Start Transaction ***//
Trans = objConn.BeginTransaction(IsolationLevel.ReadCommitted);
try
{
//*** Query 1 ***//
strSQL = "INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) " +
"VALUES ('C005','Weerachai Nukitram','[email protected]','TH','2000000','1000000')";
objCmd = new System.Data.OleDb.OleDbCommand();
objCmd.Connection = objConn;
objCmd.Transaction = Trans;
objCmd.CommandType = CommandType.Text;
objCmd.CommandText = strSQL;
objCmd.ExecuteNonQuery();
//*** Query 2 ***//
strSQL = "INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) " +
"VALUES ('C005','Weerachai Nukitram','[email protected]','TH','2000000','1000000')";
objCmd = new System.Data.OleDb.OleDbCommand();
objCmd.Connection = objConn;
objCmd.Transaction = Trans;
objCmd.CommandType = CommandType.Text;
objCmd.CommandText = strSQL;
objCmd.ExecuteNonQuery();
Trans.Commit(); //*** Commit Transaction ***//
this.lblText.Text = "Record is commit";
}
catch (Exception ex)
{
Trans.Rollback(); //*** RollBack Transaction ***//
this.lblText.Text = "Record is rollback (" + ex.Message + ")";
}
objCmd = null;
objConn.Close();
objConn = null;
|
|
|
|
|
Date :
2015-09-20 09:36:24 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ยังไงผมก็ต้องขอลองก่อนน่ะครับ
|
|
|
|
|
Date :
2015-09-20 14:42:42 |
By :
illmndraft |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2015-09-21 09:26:24 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|