ช่วยดูโค้ดให้หน่อยครับ Syntax error in UPDATE statement
เครื่องหมาย (,) น่าจะเกินน่ะครับ "OSID='"& OSID &"', " & _
Code (PHP)
sql = "update orders " & _
"set ddtran='"& ddtran &"'," & _
"howbaht ='"& howbaht &"'," & _
"noteto='"& noteto &"'," & _
"ddauto='"& ddauto &"'," & _
"OSID='"& OSID &"' " & _
"where oid=" & oid
Date :
2009-10-04 07:23:12
By :
webmaster
^
^
ขอบคุณมากครับ แก้ได้แล้ว แต่มีปัญหาอีกแล้วน่ะครับ คราวนี้หน้าใหม่ มันขึ้นว่า
Syntax error in string in query expression '' where pid =1493'.
สงสัยว่าทำไมมีปัญหาบพวกโค้ดอัปเดทข้อมูลบ่อยจังอ่ะครับ ทั้งๆที่มันก็เหมือกัน
คือเขียนหน้าอื่นแทบจะไม่ติดปัญหาเลย
Code (ASP)
sql = "update products " & _
"set catid="& catid &"," & _
"pname='"& pname &"'," & _
"pcompany='"& pcompany &"'," & _
"pprice="& pprice &"," & _
"pdiscount="& pdiscount &"," & _
"pimages='"& pimages &"'," & _
"pimagel='"& pimagel &"'," & _
"pdescriptionf='"& pdescriptionf &"'," & _
"pdescriptions='"& pdescriptions &"'," & _
"plink='"& plink &" " & _
"where pid =" & pid
Conn.Execute sql
Date :
2009-10-05 15:13:17
By :
closedtoone
Syntax error in string in query expression '' where pid =1493'.
ตรงที่ว่า where pid =1493' มันเออเรอร์ เพราะ ฟันเดี่ยวมันโผล่มาตัวนึงหน่ะครับ
Date :
2012-03-12 14:31:04
By :
ทิมมี่
pid ='1493'
Code (ASP)
sql = "update products " & _
"set catid="& catid &"," & _
"pname='"& pname &"'," & _
"pcompany='"& pcompany &"'," & _
"pprice="& pprice &"," & _
"pdiscount="& pdiscount &"," & _
"pimages='"& pimages &"'," & _
"pimagel='"& pimagel &"'," & _
"pdescriptionf='"& pdescriptionf &"'," & _
"pdescriptions='"& pdescriptions &"'," & _
"plink='"& plink &" " & _
"where pid ='" & pid & "'
Conn.Execute sql
ประวัติการแก้ไข 2012-03-16 13:54:35 2012-03-16 13:54:52
Date :
2012-03-16 13:54:12
By :
sodamax
Syntax error in UPDATE statement เช่นกันค่ะ รบกวนดูให้หน่อยค่ะหามันทุกเว็บแล้วไม่เก็ตเลย
โค้ดค่ะ
Code (VB.NET)
Private Sub DataUpDate()
Try
If txthosid.Text = "" Then
txthosid.Focus()
Exit Sub
ElseIf dtpdatein.Text = "" Then
dtpdatein.Focus()
Exit Sub
ElseIf txtnametitle.Text = "" Then
txtnametitle.Focus()
Exit Sub
ElseIf txtname.Text = "" Then
txtname.Focus()
Exit Sub
ElseIf txtsurename.Text = "" Then
txtsurename.Focus()
Exit Sub
ElseIf txtidno.Text = "" Then
txtidno.Focus()
Exit Sub
ElseIf dtpexp.Text = "" Then
dtpexp.Focus()
Exit Sub
ElseIf txtidno2.Text = "" Then
txtidno2.Focus()
Exit Sub
ElseIf dtpexp1.Text = "" Then
dtpexp1.Focus()
Exit Sub
ElseIf cmbGroup.Text = "" Then
cmbGroup.Focus()
Exit Sub
ElseIf dtpbirthdate.Text = "" Then
dtpbirthdate.Focus()
Exit Sub
ElseIf txtage.Text = "" Then
txtage.Focus()
Exit Sub
ElseIf cmbSex.Text = "" Then
cmbSex.Focus()
Exit Sub
ElseIf cmbRelig.Text = "" Then
cmbRelig.Focus()
Exit Sub
ElseIf cmbNation.Text = "" Then
cmbNation.Focus()
Exit Sub
ElseIf cmbBudha.Text = "" Then
cmbBudha.Focus()
Exit Sub
ElseIf cmbJob.Text = "" Then
cmbJob.Focus()
Exit Sub
ElseIf cmbStatus.Text = "" Then
cmbStatus.Focus()
Exit Sub
ElseIf txtfathername.Text = "" Then
txtfathername.Focus()
Exit Sub
ElseIf txtmothername.Text = "" Then
txtmothername.Focus()
Exit Sub
ElseIf txtspouse.Text = "" Then
txtspouse.Focus()
Exit Sub
ElseIf txtaddhome.Text = "" Then
txtaddhome.Focus()
Exit Sub
ElseIf txtmoo.Text = "" Then
txtmoo.Focus()
Exit Sub
ElseIf txtsoi.Text = "" Then
txtsoi.Focus()
Exit Sub
ElseIf txtroad.Text = "" Then
txtroad.Focus()
Exit Sub
ElseIf cmbProvince.Text = "" Then
cmbProvince.Focus()
Exit Sub
ElseIf cmbAmphur.Text = "" Then
cmbAmphur.Focus()
Exit Sub
ElseIf cmbDistrict.Text = "" Then
cmbDistrict.Focus()
Exit Sub
ElseIf txtpostel.Text = "" Then
txtpostel.Focus()
Exit Sub
ElseIf txtphone.Text = "" Then
txtphone.Focus()
Exit Sub
ElseIf txtaddpresent.Text = "" Then
txtaddpresent.Focus()
Exit Sub
ElseIf txtmoo1.Text = "" Then
txtmoo1.Focus()
Exit Sub
ElseIf txtsoi1.Text = "" Then
txtsoi1.Focus()
Exit Sub
ElseIf txtroad1.Text = "" Then
txtroad1.Focus()
Exit Sub
ElseIf cmbProvince2.Text = "" Then
cmbProvince2.Focus()
Exit Sub
ElseIf cmbAmphur2.Text = "" Then
cmbAmphur2.Focus()
Exit Sub
ElseIf cmbDistrict2.Text = "" Then
cmbDistrict2.Focus()
Exit Sub
ElseIf txtpostel1.Text = "" Then
txtpostel1.Focus()
Exit Sub
ElseIf txtphone1.Text = "" Then
txtphone1.Focus()
Exit Sub
ElseIf txtaddwork.Text = "" Then
txtaddwork.Focus()
Exit Sub
ElseIf txtno.Text = "" Then
txtno.Focus()
Exit Sub
ElseIf txtmoo2.Text = "" Then
txtmoo2.Focus()
Exit Sub
ElseIf txtsoi2.Text = "" Then
txtsoi2.Focus()
Exit Sub
ElseIf txtroad2.Text = "" Then
txtroad2.Focus()
Exit Sub
ElseIf cmbProvince3.Text = "" Then
cmbProvince3.Focus()
Exit Sub
ElseIf cmbAmphur3.Text = "" Then
cmbAmphur3.Focus()
Exit Sub
ElseIf cmbDistrict3.Text = "" Then
cmbDistrict3.Focus()
Exit Sub
ElseIf txtpostel2.Text = "" Then
txtpostel2.Focus()
Exit Sub
ElseIf txtphone2.Text = "" Then
txtphone2.Focus()
Exit Sub
ElseIf txtcontactemer.Text = "" Then
txtcontactemer.Focus()
Exit Sub
ElseIf txtrelation.Text = "" Then
txtrelation.Focus()
Exit Sub
ElseIf txtphone3.Text = "" Then
txtphone3.Focus()
Exit Sub
ElseIf cmbRight.Text = "" Then
cmbRight.Focus()
Exit Sub
ElseIf cmbRightName.Text = "" Then
cmbRightName.Focus()
Exit Sub
ElseIf txtreactions.Text = "" Then
txtreactions.Focus()
Exit Sub
ElseIf txtcongenital.Text = "" Then
txtcongenital.Focus()
Exit Sub
ElseIf txtrequirestre.Text = "" Then
txtrequirestre.Focus()
Exit Sub
End If
Dim DAu As OleDbDataAdapter = New OleDbDataAdapter
Dim DSu As DataSet = New DataSet
DAu.SelectCommand = New OleDbCommand("SELECT*FROM tblpatient WHERE(HospitalNo)='" & txthosid.Text & "' ", CN)
DSu.Clear()
DAu.Fill(DSu, "tblpatient")
If DSu.Tables(0).Rows.Count > 0 Then
Dim strSQL = "UPDATE tblpatient SET HospitalNo='" & Me.txthosid.Text & "',Datein='" & Me.dtpdatein.Text & "',Nametitle='" & Me.txtnametitle.Text & "',Name='" & Me.txtname.Text & "',surename='" & Me.txtsurename.Text & "',IDNo='" & Me.txtidno.Text & "',Exp=#'" & Me.dtpexp.Text & "'#,IDNo2='" & Me.txtidno2.Text & "',Exp1='" & Me.dtpexp1.Text & "',Blood='" & Me.cmbGroup.Text & "',BirthDate='" & Me.dtpbirthdate.Text & "',Age='" & Me.txtage.Text & "',Sex='" & Me.cmbSex.Text & "',Origin='" & Me.cmbRelig.Text & "',Nationality='" & Me.cmbNation.Text & "',Religion= '" & Me.cmbBudha.Text & "',Occupation='" & Me.cmbJob.Text & "',Status='" & Me.cmbStatus.Text & "',FatherName='" & Me.txtfathername.Text & "',MotherName='" & Me.txtmothername.Text & "',SpouseName='" & Me.txtspouse.Text & "',AddHome='" & Me.txtaddhome.Text & "',Moo='" & Me.txtmoo.Text & "',Soi='" & Me.txtsoi.Text & "',Road='" & Me.txtroad.Text & "',Province='" & Me.cmbProvince.Text & "',Amphur='" & Me.cmbAmphur.Text & "',District='" & Me.cmbDistrict.Text & "',Postel='" & Me.txtpostel.Text & "',Phone='" & Me.txtphone.Text & "',Addpresent='" & Me.txtaddpresent.Text & "',Moo1='" & Me.txtmoo1.Text & "',Soi1='" & Me.txtsoi1.Text & "',Road1='" & Me.txtroad1.Text & "',Province2='" & Me.cmbProvince2.Text & "',Amphur2='" & Me.cmbAmphur2.Text & "',District2='" & Me.cmbDistrict2.Text & "',Postel1='" & Me.txtpostel1.Text & "',Phone1='" & Me.txtphone1.Text & "',AddWork='" & Me.txtaddwork.Text & "',No='" & Me.txtno.Text & "',Moo2='" & Me.txtmoo2.Text & "',Soi2='" & Me.txtsoi2.Text & "',Road2='" & Me.txtroad2.Text & "',Province3='" & Me.cmbProvince3.Text & "',Amphur3='" & Me.cmbAmphur3.Text & "',District3='" & Me.cmbDistrict3.Text & "', Postel2='" & Me.txtpostel2.Text & "',Phone2='" & Me.txtphone2.Text & "',ContactEmergency='" & Me.txtcontactemer.Text & "',Relation='" & Me.txtrelation.Text & "',Phone3='" & Me.txtphone3.Text & "',Right='" & Me.cmbRight.Text & "',RightName= '" & Me.cmbRightName.Text & "',Reactions='" & Me.txtreactions.Text & "',CongenitalDisease='" & Me.txtcongenital.Text & "',RequiresTreatment='" & Me.txtrequirestre.Text & "' WHERE (HospitalNo)='" & txthosid.Text & "' "
CN.Open()
Dim dCmdx As OleDbCommand = New OleDbCommand(strSQL, CN)
dCmdx.ExecuteNonQuery()
dCmdx.Dispose()
MessageBox.Show("ระบบได้ทำการอัพเดทข้อมูลเรียบร้อยแล้ว", "การประมวลผลข้อมูล", MessageBoxButtons.OK, MessageBoxIcon.Information)
Call DefaulData()
Call Defaulbtn()
Call DefaulSearch()
Else
MessageBox.Show("ระบบไม่สามารถทำการอัพเดทข้อมูลได้", "การประมวลผลข้อมูล", MessageBoxButtons.OK, MessageBoxIcon.Error)
txthosid.Focus()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
CN.Close()
End Sub
ไม่ทราบว่าต้องแก้ตรงไหนค่ะ รบกวนท่านผู้รู้หน่อยค่ะติดอยู่ตัวเดียวเป็น visual basic 2008 & Access 2007 ขอบคุณล่วงหน้าค่ะ
หรือจะส่งทางเมล์ก็ได้น๊ะค่ะ [email protected]
Date :
2012-04-17 14:45:36
By :
nutty
เยอะเกินครับ ไล่ไม่ออก ลองดูพวกคำสงวนด้วยครับ
Date :
2012-04-17 17:41:40
By :
webmaster
Code (VB.NET)
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Dim sqledit As String
txtName.Focus()
Dim cm As New OleDbCommand
If MsgBox("ต้องการแก้ไขข้อมูล", CType(vbQuestion + vbYesNo, MsgBoxStyle), "คำยืนยัน") = vbYes Then
Dim sqlAdd As String = ""
sqledit = "UPDATE tblProduct SET"
sqledit = sqledit + " SET PROID='" & txtID.Text & "',"
sqledit = sqledit + " Proname='" & txtName.Text & "',"
sqledit = sqledit + " ModelName='" & txtModelName.Text & "',"
sqledit = sqledit + " Model='" & txtModel.Text & "',"
sqledit = sqledit + " Prodetail ='" & txtDetail.Text & ","
sqledit = sqledit + " WHERE "
sqledit = sqledit + " ProID" & txtID.Text
With cm
.CommandType = CommandType.Text
.CommandText = sqledit
.Connection = Conn
.ExecuteNonQuery() << syntax error update statement ตามที่หัวข้อเลยครับ ช่วยทีครับรบกวนด้วย
End With
MessageBox.Show("แก้ไขข้อมูล เรียบร้อยแล้ว", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
ShowAllProduct()
End If
End Sub
Date :
2012-06-12 16:53:01
By :
Mr'ก
Code (VB.NET)
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Dim sqledit As String
txtName.Focus()
Dim cm As New OleDbCommand
If MsgBox("ต้องการแก้ไขข้อมูล", CType(vbQuestion + vbYesNo, MsgBoxStyle), "คำยืนยัน") = vbYes Then
Dim sqlAdd As String = ""
sqledit = "UPDATE tblProduct SET"
sqledit = sqledit + " Proname='" & txtName.Text & "',"
sqledit = sqledit + " ModelName='" & txtModelName.Text & "',"
sqledit = sqledit + " Model='" & txtModel.Text & "',"
sqledit = sqledit + " Prodetail ='" & txtDetail.Text & "',"
sqledit = sqledit + " WHERE "
sqledit = sqledit + " ProID ='" & txtID.Text &"'"
With cm
.CommandType = CommandType.Text
.CommandText = sqledit
.Connection = Conn
.ExecuteNonQuery()
End With
MessageBox.Show("แก้ไขข้อมูล เรียบร้อยแล้ว", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
ShowAllProduct()
End If
End Sub
ประวัติการแก้ไข 2012-06-12 19:06:55
Date :
2012-06-12 19:05:32
By :
bangbang111
ขอบคุณนะครับคุณ bangbang111 แต่ผมยังติด เหมือนเดิมไม่ทราบว่าตัวแปรมีส่วนเกี่ยวข้องด้วยหรือเปล่าครับที่ทำให้มัน error ครับ หรือการเรียงลำดับของแต่ละคำสั่งอะครับ ถ้าใครรู้ช่วยทีครับทำมาหลายวันแล้วครับ
Date :
2012-06-13 09:42:09
By :
Mr'ก
Error เหมือนกันครับ รบกวนด้วยครับ งง มา 3 วันแล้วครับ รบกวนผู้รู็บอกที Error Syntax Error in Update Satement ครับ
Code (VB.NET)
Private Sub Doc()
' อ่านข้อมูลเก็บไว้ใน Dataset
Dim Sql As String = "SELECT * FROM Document WHERE Key='KEY'"
_Cmd = New OleDbCommand(Sql, _Conn)
'Dim Adapter As New OleDbDataAdapter(_Cmd)
'_Dataset = New DataSet
'Adapter.Fill(_Dataset, "Doc")
Dim Reader As OleDbDataReader = _Cmd.ExecuteReader()
Reader.Read()
Dim MM As String = Reader("Month")
Dim No As String = Reader("No")
Dim MMnow As String = Month(Now)
Dim YYnow As String = Mid(Year(Now), 3)
Dim Document As String = ""
Dim Mon As String
Dim Run As String
If MMnow <> MM Then
No = 0
Document = "R" & YYnow & "0" & MMnow & "/" & "000" & No + 1
Else
Mon = "0" & MMnow
Mon = (Microsoft.VisualBasic.Right(Mon, 2))
Run = "000" & No + 1
Run = (Microsoft.VisualBasic.Right(Run, 4))
Document = "R" & YYnow & Mon & "/" & Run
End If
Sql = "UPDATE Document SET Year='" & YYnow & "', Month='" & MMnow & "', No='" & No + 1 & "',Doc='" & Document & "' WHERE Key='KEY'"
_Cmd = New OleDbCommand(Sql, _Conn)
_Reader = _Cmd.ExecuteReader()
' _Cmd.Parameters.AddWithValue("YY", YYnow)
' _Cmd.Parameters.AddWithValue("MM", MMnow)
' _Cmd.Parameters.AddWithValue("No", No + 1)
' _Cmd.Parameters.AddWithValue("Do", Document)
Dim Affected As Integer = _Cmd.ExecuteNonQuery
If Affected < 1 Then
MsgBox("เกิดข้อผิดพลาดในการแก้ไขข้อมูล!", MsgBoxStyle.OkOnly, "ผลการแก้ไข")
Else
MsgBox("ข้อมูลถูกแก้ไขแล้ว!", MsgBoxStyle.OkOnly, "ผลการแก้ไข")
End If
End Sub
Date :
2013-01-17 10:26:14
By :
Natthawut
สำหรับคุณ Natthawut นะครับ
เท่าที่ผมดู น่าจะเป็นตรง No='" & No + 1 & "' ตรงนี้น่าจะเป็น
No=" & No + 1 & " หรือเปล่าครับ เพราะว่าน่าจะเก็บข้อมูลเป็นตัวเลข
ปล. ถ้าเป็นตัวเลขที่ผมเรียนมา รู้สึกจะไม่ต้องใส่เครื่องหมาย ' นะครับ
Date :
2013-02-22 17:17:44
By :
Cecchino
Load balance : Server 04