|
 |
|
C# บันทึกข้อมูลไม่ได้อ่ะคับ มันขึ้น error อ่ะคับแก้ไม่ได้เลยคับช่วยผมหน่อยคับ |
|
 |
|
|
 |
 |
|


Code (C#)
private void Psave()
{
objconn.Conn();
string strSQL;
strSQL = "Select Per_ID,Per_CardID,Per_Sex,Per_Firstname,Per_Lastname,Per_Add,Per_District,Per_Province,Per_Postcode,Per_Phon,Per_Date,Per_Username,Per_Password,Per_Email,De_ID from Personels order by Per_ID";
sqlCMD = new SqlCommand(strSQL, objconn.conn1);
sqlDR = sqlCMD.ExecuteReader();
if (sqlDR.Read())
{
strSQL = "Update Personels set Per_CardID = '" + maskedTextBox1.Text + "'";
strSQL += ",Per_Sex = '" + comboBox1.Text + "'";
strSQL += ",Per_Firstname = '" + txtName.Text + "'";
strSQL += ",Per_Lastname = '" + txtlastname.Text + "'";
strSQL += ",Per_Add = '" + txtAdd.Text + "'";
strSQL += ",Per_District = '" + txtOum.Text + "'";
strSQL += ",Per_Province = '" + ComboBox.Text + "'";
strSQL += ",Per_Postcode = '" + txtPostcard.Text + "'";
strSQL += ",Per_Phon = '" + txtPhone.Text + "'";
strSQL += ",Per_Date = '" + txtdate.Text + "'";
strSQL += ",Per_Username = '" + dateTimePicker1.Value.ToString("s") + "'";
strSQL += ",Per_Password = '" + txtpass.Text + "'";
strSQL += ",Per_Email = '" + txtmail.Text + "'";
strSQL += ",De_ID = '" + comboBox2.Text + "'";
strSQL += "where Per_ID = '" + txtID.Text +"'";
}
else
{
strSQL = "Insert into Personels(Per_ID,Per_CardID,Per_Sex,Per_Firstname,Per_Lastname,Per_Add,Per_District,Per_Province,Per_Postcode,Per_Phon,Per_Date,Per_Username,Per_Password,Per_Email,De_ID)";
strSQL += "Values('" + txtID.Text + "','" + maskedTextBox1.Text + "','" + comboBox1.Text + "'";
strSQL += ",'" + txtName.Text + "','" + txtlastname.Text + "','" + txtAdd.Text + "','" + txtOum.Text + "','" + ComboBox.Text + "'";
strSQL += ",'" + txtPostcard.Text + "','" + txtPhone.Text + "','" + txtdate.Text + "'";
strSQL += ",'" + dateTimePicker1.Value.ToString("s") + "','" + txtpass.Text + "','" + txtmail.Text + "','" + comboBox2.Text + "')";
}
sqlDR.Close();
sqlCMD = new SqlCommand(strSQL, objconn.conn1);
int numRec = sqlCMD.ExecuteNonQuery();
if (numRec > 0)
{
MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว", "บันทึกข้อมูล");
}
else
{
MessageBox.Show("ไม่สามารถบันทึกข้อมูลได้", "บันทึกข้อมูล");
}
txtID.Text = AddPer_ID().ToString();
showpesonel();
}
Tag : Ms SQL Server 2012, VB.NET, C#

|
ประวัติการแก้ไข 2013-09-08 21:13:29 2013-09-08 21:15:47
|
 |
 |
 |
 |
Date :
2013-09-08 21:12:05 |
By :
coutiho |
View :
923 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ในอีกเครื่องที่ทำบันทึกได้อยู่อ่ะคับ แต่พอทำอีกเครื่องบันทึกไม่ได้อ่ะคับ
|
ประวัติการแก้ไข 2013-09-09 10:38:02
 |
 |
 |
 |
Date :
2013-09-09 10:37:28 |
By :
coutiho |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ยังไงอ่ะคับ
|
 |
 |
 |
 |
Date :
2013-09-13 11:29:52 |
By :
coutiho |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
น่าจะมีปัญหากับฟิลด์ที่เป็นวันที่ครับ
คิดว่าน่าจะเป็น Per_Date ซึ่งผูกไว้กับ txtdate.Text (มันอยู่ตรงไหน ผมเห็นมีแต่ dateTimePicker1 ที่น่าจะใช่)
ถ้าอีกเครื่องได้ แต่เครื่องนี้ไม่ได้ ก็น่าจะมาจากการต้้ง format วันที่ไม่เหมือนกัน
ลอง debug ดึงค่า strSQL มาให้ดูหน่อยได้ไหมครับ
|
 |
 |
 |
 |
Date :
2013-09-13 11:36:37 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วคับ
ขอบคุณมากคับ
|
 |
 |
 |
 |
Date :
2013-09-14 19:08:43 |
By :
coutiho |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|