 |
|
VB.NET โค้ดแก้ไขข้อมูลมัน Error ค่ะไม่สามารถแก้ไขข้อมูลได้ |
|
 |
|
|
 |
 |
|
Code (VB.NET)
Private Sub edit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles edit.Click
Dim sqlEdit As String = ""
Dim tmpRowsAffected As Long
If (txtรหัสอสม.Text = "") Or (txtรหัสประชาชน.Text = "") Or (txtคำนำหน้า.Text = "") Or (txtชื่อ.Text = "") Or (txtนามสกุล.Text = "") Or (txtที่อยู่.Text = "") Or (txtวันเกิด.Text = "") Or (txtเพศ.Text = "") Or (txtอายุ.Text = "") Or (txtอาชีพ.Text = "") Or (txtสถานะ.Text = "") Or (txtวันเข้าร่วม.Text = "") Or (txtเขตรับผิดชอบ.Text = "") Then
MessageBox.Show("กรุณาป้อนข้อมูลให้ครบ !!!", "ผลการตรวจสอ()", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtรหัสอสม.Focus()
Exit Sub
End If
If MessageBox.Show("คุณต้องการแก้ไขข้อมูลวัสดุ ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
sqlEdit = "Update Member Set Member_Id='" + txtรหัสอสม.Text + "',Member_Idpeople ='" + txtรหัสประชาชน.Text + "',Member_Title='" + txtคำนำหน้า.Text + "',Member_Firstname='" + txtชื่อ.Text + "',Member_Lastname='" + txtนามสกุล.Text + "',Member_Address='" + txtที่อยู่.Text + "',Member_Birthday='" + txtวันเกิด.Text + "',Member_Sex='" + txtเพศ.Text + "',Member_Age ='" + txtอายุ.Text + "',Member_Vocation ='" + txtอาชีพ.Text + "',Member_Marry ='" + txtสถานะ.Text + "',Member_Datejoin ='" + txtวันเข้าร่วม.Text + "',Member_Responsible ='" + txtเขตรับผิดชอบ.Text + "' Where Member_Id='" + txtรหัสอสม.Text + "'"
End If
Try
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = DBConnString.strConn
.Open()
End With
Dim comUpdate = New OleDbCommand
With comUpdate
.CommandType = CommandType.Text
.CommandText = sqlEdit
.Connection = Conn
tmpRowsAffected = .ExecuteNonQuery()
End With
If tmpRowsAffected = 0 Then
MessageBox.Show("รหัสที่คุณป้อนไม่มี !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtรหัสอสม.Focus()
txtรหัสอสม.SelectAll()
Exit Sub
End If
Catch ErrorToEdit As Exception
MessageBox.Show("ไม่สามารถแก้ไขข้อมูลได้ เนื่องจาก " & ErrorToEdit.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtรหัสอสม.Focus()
txtรหัสอสม.SelectAll()
Exit Sub
Conn.Close()
End Try
ShowData()
MessageBox.Show("แก้ไขข้อมูล เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
ClearAllData()
txtรหัสอสม.Focus()
End Sub
Tag : .NET, VB.NET
|
ประวัติการแก้ไข 2013-02-21 01:21:53 2013-02-21 01:22:22
|
 |
 |
 |
 |
Date :
2013-02-21 01:20:49 |
By :
Wantanee |
View :
1152 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Quote:Update Member Set Member_Id='" + txtรหัสอสม.Text + "',Member_Idpeople ='" + txtรหัสประชาชน.Text + "',Member_Title='" + txtคำนำหน้า.Text + "',Member_Firstname='" + txtชื่อ.Text + "',Member_Lastname='" + txtนามสกุล.Text + "',Member_Address='" + txtที่อยู่.Text + "',Member_Birthday='" + txtวันเกิด.Text + "',Member_Sex='" + txtเพศ.Text + "',Member_Age ='" + txtอายุ.Text + "',Member_Vocation ='" + txtอาชีพ.Text + "',Member_Marry ='" + txtสถานะ.Text + "',Member_Datejoin ='" + txtวันเข้าร่วม.Text + "',Member_Responsible ='" + txtเขตรับผิดชอบ.Text + "' Where Member_Id='" + txtรหัสอสม.Text + "'"
ผู้ร้ายคือหนึ่งในนี้แหละ หาดู
sql มันไม่แปลง type ให้เหมือน vb
อะไรเป็น int อะไรเป็น string ก็ส่งไปให้ถูก datatype
|
 |
 |
 |
 |
Date :
2013-02-21 08:57:58 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
datatype กับ ข้อมูลที่ส่งเข้าไป ไม่ตรงกันครับ เช่น datatype เป็น int แต่ส่ง string เข้าไป เป็นต้น  
|
 |
 |
 |
 |
Date :
2013-02-21 10:17:28 |
By :
slurpee55555 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แนะนำนอกเรื่องนิดนึงครับ
น่าจะตั้งชื่อพวก textbox หรืออื่น ๆ เป็นภาษาอังกฤษนะ
ไม่ต้องถูกเป๊ะก็ได้ เอาแค่ดูแล้วเราเข้าใจว่าคืออะไรก็ได้ครับ
|
 |
 |
 |
 |
Date :
2013-02-21 18:24:21 |
By :
N3BUL4 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ไขได้แล้วค่ะขอบคุณพี่ๆทุกคนมากค่ะ
|
 |
 |
 |
 |
Date :
2013-02-21 20:19:19 |
By :
Wantanee |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|