 |
|
อีกแล้วครับท่าน error ตามเคย syntax error in INSERT INTO และ UPDATE ครับ |
|
 |
|
|
 |
 |
|
เงียบ ทำเองก็แล้ว ...
|
 |
 |
 |
 |
Date :
2010-06-26 23:08:31 |
By :
adunafah |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
dim con as new sqlconnection
dim com as new sqlcommand
dim tr as sqltransaction
dim sb as new stringbuider
dim strCon as string
dim strSql as string
private sub ConnectionAccess()
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;;Data Source=C:\\committee.mdb;Jet OLEDB:Database Password="
if con.state = con.open() then con.close()
con.connectionstring = strCon
con.open()
end if
end sub
private sub CommandData()
ConnectionAccess()
tr = con.begintransaction()
try
select case actionflag
case "Add"
sb.remove(0,sb.lenght)
sb.append("insert into committee (committee_id,memberid,password,level)")
sb.append(" values('" & txtcommit_id.text & "',")
sb.append("'" & txtmemberid.text & "',")
sb.append("'" & txtpassword.text & "',")
sb.append("'" & txtlevel.text & "')")
strSql = sb.tostring()
case "Edit"
sb.remove(0,sb.lenght)
sb.append("update committee set ")
sb.append(" memberid = '" & txtmemberid.text & "',")
sb.append(" password = '" & txtpassword.text & "',")
sb.append(" level = '" & txtlevel.text & "'")
sb.append(" where committee_id = '" & txtcommit.text & "'")
strSql = sb.tostring()
end select
com = new sqlcommand(strSql,con)
com.transaction = tr;
com.executenonquery()
tr.commit()
catch (Exception ex)
tr.rollback()
msgbox(ex.tostring)
con.close()
end try
end sub
ไม่แน่ใจว่าถูกหรือเปล่า ลองเอาไปใช้ดูครับ
|
 |
 |
 |
 |
Date :
2010-06-28 09:39:01 |
By :
tee |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
level เป็น unmeaning reserved word ของ sql statement เฉพาะ access ค่ะ
ความหมายของ unmeaning reserved word ก็ตรงตัวคือเป็น reserved word เจ๋ยๆ ยังไม่ได้ใช้ทำอะไร
(แล้วจะมีไว้ทำไมเนี่ย )
เวลาเรียกใช้ sql statement ของ access
ขอแนะนำให้ใส่ [] ครอบชื่อ field และชื่อ table ให้เป็นโดยปริยายดีกว่าค่ะ
reference
MsAccess 2007 SQL reserved word
|
 |
 |
 |
 |
Date :
2010-06-28 11:25:12 |
By :
blurEyes |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีคนใจดีมาตอบเสียที 
มันเป็น key ห้ามใช้ตั้งชื่อ field ถ้าจะตั้งต้องใช้ [] ครอบ แล้วก็เอาไปปฏิบัติให้เป็นนิสัยด้วย
|
 |
 |
 |
 |
Date :
2010-06-28 11:30:22 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณพี่ blurEyes และ tungman มากครับ
ผมไม่รู้ว่า level เป็น key ที่ต้องห้าม
พอดีผมไม่ได้ รัน ดูก็เลยไม่รู้
*แต่ก็เป็นความรู้เพิ่มเติมครับ
|
 |
 |
 |
 |
Date :
2010-06-28 13:35:16 |
By :
tee |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ຂອບໃຈ ທີ່ໃຫ້ຄວາມຮູ້
|
 |
 |
 |
 |
Date :
2012-06-04 11:43:40 |
By :
sabat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|