|
 |
|
ใส่ code update คิดว่าถูกหมดแล้วแต่ยังผิด ช่วยแก้ไขให้หน่อยครับ |
|
 |
|
|
 |
 |
|
ลองเอา code update หลายอันในโปรเจคที่แก้ไขได้มาทำแล้ว แต่ก็ยังขึ้นผิดพลาดอยู่ดีช่วยหน่อยนะครับ
Code
If confirm("คุณต้องการแก้ไขหรือไม่?") = vbNo Then Return
oledb = "update client set c_pass=@pass, c_name=@name, nickname=@nickname, born=@born, address=@address,tel=@tel where username='" & txt_add_username.Text & "'"
cmd = New OleDbCommand(oledb, cn)
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("pass", txt_edit_password.Text)
cmd.Parameters.AddWithValue("name", txt_edit_name.Text)
cmd.Parameters.AddWithValue("nickname", txt_edit_nickname.Text)
cmd.Parameters.AddWithValue("born", date_edit_born.Value)
cmd.Parameters.AddWithValue("address", txt_edit_address.Text)
cmd.Parameters.AddWithValue("tel", txt_add_tel.Text)
cmd.Parameters.AddWithValue("username", txt_edit_username.Text)
If cmd.ExecuteNonQuery() = 0 Then
msg_error("ไม่สามารถแก้ไขได้")
Else
msg_ok("แก้ไขสำเร็จ")
End If



ปล. แท็กภาษาหลักผิดก็ขออภัยครับ
Tag : .NET, Ms Access, VS 2010 (.NET 4.x)

|
|
 |
 |
 |
 |
Date :
2018-02-19 01:56:55 |
By :
Zebastien |
View :
972 |
Reply :
10 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง เช็ค text username ดูหรือยังคับ เพราะถ้ากดเลือก text จาก datagridview ด้านขวามือ โอกาสเป็นไปได้ทีี่จะติด blank space มาด้วยครับเช่น username อาจจะกลายเป็น
"dfsdf "
ถ้าไม่บัคดูก้ลองแก้ query เป็น
Code (VB.NET)
where username='" & txt_add_username.Text.trim & "'"
เพื่อกำจัด blank space ครับ
|
 |
 |
 |
 |
Date :
2018-02-19 10:08:26 |
By :
thongchai001 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
oledb = "update client set c_pass=@pass, c_name=@name, nickname=@nickname, born=@born, address=@address,tel=@tel where username=@username"
|
 |
 |
 |
 |
Date :
2018-02-19 10:53:21 |
By :
OOP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แนะนำให้เพิ่ม ID ขึนมา
จะลดข้อผิดพลาดในการพิมพ์
และ
จะแก้ไข username ได้ด้วย
|
 |
 |
 |
 |
Date :
2018-02-19 11:25:00 |
By :
Dr.K |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณทุกคอมเม้นนะครับ แต่แก้แล้วก็ยังเหมือนเดิม
|
 |
 |
 |
 |
Date :
2018-02-19 17:13:12 |
By :
Zebastien |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือถ้าเราแอดข้อมูลเข้าไปใหม่ เราจะสามารถแก้ไขได้ แต่ถ้าเราไปแก้ไขเลยโดยไม่แอดอะไรเข้าไปมันจะเป็นดังรูปครับ

|
 |
 |
 |
 |
Date :
2018-02-19 17:48:50 |
By :
Zebastien |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใน cmd.Parameters.AddWithValue ใส่ @ ด้วยสิครับ
Code (VB.NET)
cmd.Parameters.AddWithValue("@pass", txt_edit_password.Text)
ตรง where ก็ใช้ พารามิเตอร์ด้วยครับ
Code (VB.NET)
oledb = "update client set c_pass=@pass, c_name=@name, nickname=@nickname, born=@born, address=@address,tel=@tel where username=@username"
เป็น
Code (VB.NET)
If confirm("คุณต้องการแก้ไขหรือไม่?") = vbNo Then Return
oledb = "update client set c_pass=@pass, c_name=@name, nickname=@nickname, born=@born, address=@address,tel=@tel where username=@username"
cmd = New OleDbCommand(oledb, cn)
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("@pass", txt_edit_password.Text)
cmd.Parameters.AddWithValue("@name", txt_edit_name.Text)
cmd.Parameters.AddWithValue("@nickname", txt_edit_nickname.Text)
cmd.Parameters.AddWithValue("@born", date_edit_born.Value)
cmd.Parameters.AddWithValue("@address", txt_edit_address.Text)
cmd.Parameters.AddWithValue("@tel", txt_add_tel.Text)
cmd.Parameters.AddWithValue("@username", txt_edit_username.Text)
If cmd.ExecuteNonQuery() = 0 Then
msg_error("ไม่สามารถแก้ไขได้")
Else
msg_ok("แก้ไขสำเร็จ")
End If
|
 |
 |
 |
 |
Date :
2018-02-19 18:55:22 |
By :
pakyaudio |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
#Comment 6
ขอบคุณครับเดี๋ยวลองทำก่อนนะครับ
|
 |
 |
 |
 |
Date :
2018-02-19 20:10:21 |
By :
zebastien |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เปลี่ยนทุกอย่างก็เข้าเงื่อนไขเดิม ไม่เข้าใจครับ
Code
If confirm("คุณต้องการแก้ไขข้อมูลลูกค้าหรือไม่ ?") = vbNo Then Return
connect()
oledb = String.Format("update client set c_pass='{0}', c_name='{1}', nickname='{2}', born='{3}', address='{4}',tel='{5}',point='{6}' where username='{7}'", txt_edit_password.Text, txt_edit_name.Text, txt_edit_nickname.Text, date_edit_born.Value, txt_edit_address.Text, txt_edit_tel.Text, txt_edit_point.Text, txt_add_username.Text)
If cmd_excuteNonquery() = 0 Then
msg_error("ไม่สามารถแก้ไขได้")
Else
msg_ok("สามารถแก้ไขได้")
load_customer()
txt_edit_address.Text = ""
txt_edit_name.Text = ""
txt_edit_nickname.Text = ""
txt_edit_password.Text = ""
txt_edit_point.Text = ""
txt_edit_tel.Text = ""
txt_edit_username.Text = ""
End If
|
ประวัติการแก้ไข 2018-02-19 23:21:18
 |
 |
 |
 |
Date :
2018-02-19 23:16:10 |
By :
Zebastien |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|