สอบถามปัญหาเกี่ยวกับการใช้ if ในการ Login หน่อยครับ
ลอง bug ค่า intCount ดูยังครับ ว่ามันได้ค่าอะไรมา
แต่ผมเข้าใจว่า ค่า intCount มัน cast ค่าจาก objCmd ไม่ได้อะครับ
Date :
2012-09-12 12:18:29
By :
mixarstudio
เชคแล้ว มันขึ้นอันนี้ครับ ยังไงดี
Record is rollback (ExecuteScalar requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.)
Date :
2012-09-14 10:11:28
By :
Chunate
เงียบเลย ยังแก้ไม่ได้เลยค้าบ บ
Date :
2012-09-14 21:51:41
By :
Chunate
คุณไปใช้ Transaction ตอนไหนครับ
Date :
2012-09-14 21:55:08
By :
mr.win
ก็คือ ตรวจสอบความผิดพลาดดูครับ แล้ว มันแสดงข้อความข้างต้น ที่ ลาเบล
อันนี้ที่ล่าสุดครับ ยังเ็นเพื่อนเดิมครับ
Code (C#)
SqlConnection objConn = null;
string strConnString = null;
StringBuilder strSQL = default(StringBuilder);
SqlCommand objCmd = null;
SqlTransaction Trans;
int intCount = 0;
//*** Open Connection ***'
strConnString = "Server=(local);UID=poorivat;PASSWORD=poorivat;database=Project Train;Max Pool Size=400;Connect Timeout=600;";
objConn = new SqlConnection();
objConn.ConnectionString = strConnString;
objConn.Open();
Trans = objConn.BeginTransaction(IsolationLevel.ReadCommitted);
try
{
//*** Check Login ***'
strSQL = new StringBuilder();
strSQL.Append(" SELECT RolID FROM Member ");
strSQL.Append(" WHERE UserName = @sUsername ");
strSQL.Append(" AND Password = @sPassword ");
objCmd = new SqlCommand(strSQL.ToString(), objConn);
objCmd.Parameters.Add("@sUsername", SqlDbType.VarChar).Value = this.txtUsername.Text;
objCmd.Parameters.Add("@sPassword", SqlDbType.VarChar).Value = this.txtPassword.Text;
intCount = (int)objCmd.ExecuteScalar();
objConn.Close();
objConn = null;
if (intCount == 0)
{
this.LblStatus.ForeColor = System.Drawing.Color.Red;
this.LblStatus.Text = "User or Password ผิดกรุณาตรวจสอบ";
}
else if (intCount == 1)
{
Session["strUsername"] = this.txtUsername.Text;
Response.Redirect("MainPage.aspx");
}
else if (intCount == 2)
{
Session["strUsername"] = this.txtUsername.Text;
Response.Redirect("MemberPage.aspx");
}
Trans.Commit();
}
catch (Exception ex)
{
Trans.Rollback(); //*** RollBack Transaction ***//
this.LblStatus.Text = "Record is rollback (" + ex.Message + ")";
Date :
2012-09-14 22:00:32
By :
Chunate
แหงะ ผมผิดเอง พอเอา Transaction ออก ก็ล๊อคอินได้ เหมือนเดิม แต่สงสัยคำถามเดิมที่ว่า เวลาเราพิมพ์ผิด ทำไม ผมตั้งให้แสดงข้อความว่า
"User or Password ผิดกรุณาตรวจสอบ";
ทำไม ถึงไม่โชว์ แต่กลายเป็น เออเร่อ เฉย
บรรทัดนี้อ่ะครับ
Date :
2012-09-14 22:04:59
By :
Chunate
แหงะ เงียบเลย ไม่มีใครมาตอบเลย เหรอ...
Date :
2012-09-16 00:01:42
By :
Chunate
ลอง Watch ดูซิครับว่า objCmd มันเป็นค่า null หรือเปล่า ถ้าใช่ก็แปลว่าโปรแกรมมัน Crash ตั้งแต่ตรงนั่นครับก็เลยไม่ไปถึง "User or Password ผิดกรุณาตรวจสอบ"; ตามที่เขียนไว้ครับ
Date :
2012-09-16 01:07:37
By :
pStudio
Load balance : Server 00