sql statement error, cant find error

darkcat02

Active member
Joined
Mar 4, 2009
Messages
38
Programming Experience
1-3
hi everyone... this error has been bugging me for a week... can anyone find the error for me... ive been getting an error on the connection on the database... but i see no error on my code... thanks

VB.NET:
Public Function GetConnect()
        conn = New OleDbConnection
        conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=InstruIO.mdb"

        Return conn
    End Function

Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim check As Integer
        Dim cmdSHEDUGM As New OleDbCommand
        Dim daSHEDUGM As New OleDbDataAdapter
        Dim dsSHEDUGM As New DataSet
        Dim dtSHEDUGM As New DataTable

        'Edit
        If txtMIndex.Text = "" Then
            MsgBox("Data is not completed", MsgBoxStyle.OkOnly)
        Else
            If MsgBox("Are you sure to edit data with Master Index : " & txtMIndex.Text & " ?", MsgBoxStyle.OkCancel, "Edit confirm") = MsgBoxResult.Cancel Then
                ' do nothing
            Else
                Try
                    conn = GetConnect()
                    conn.Open()
                    cmdSHEDUGM = conn.CreateCommand

                    If remarks.Checked = True Then
                        remarks.Tag = True
                    Else
                        remarks.Tag = False
                    End If

                    Dim a As String

                    a = "UPDATE SHEDUGM SET MASTERINDEX='" & txtMIndex.Text & _
                    "', SITE='" & txtSite.Text & _
                    "', PLANT='" & txtPlant.Text & _
                    "', TAG='" & txtTag.Text & _
                    "', FLDTAG='" & txtFldtag.Text & _
                    "', DCSTAG='" & txtDcstag.Text & _
                    "', AUXTAG='" & txtAuxtag.Text & _
                    "', CONTAG='" & txtContag.Text & _
                    "', FLDSYS='" & txtFldsys.Text & _
                    "', DLSYS='" & txtDlsys.Text & _
                    "', AUXSYS='" & txtAuxsys.Text & _
                    "', SERVICE='" & txtService.Text & _
                    "', FUNCTION='" & txtFunction.Text & _
                    "', EQUIPTAG='" & txtEquiptag.Text & _
                    "', OSPAS='" & txtOspas.Text & _
                    "', IOTYPE='" & txtIotype.Text & _
                    "', SIGNAL='" & txtSignal.Text & _
                    "', POWER='" & txtPower.Text & _
                    "', SOE='" & txtSoe.Text & _
                    "', IOREDUNDANCY='" & txtIoredundancy.Text & _
                    "', ENGRANG='" & txtEngrang.Text & _
                    "', ENGUNIT='" & txtEngunit.Text & _
                    "', CALRANG='" & txtCalrang.Text & _
                    "', CALUNIT='" & txtCalunit.Text & _
                    "', ALARM-HHH='" & txtAlarmhhh.Text & _
                    "', ALARM-HH='" & txtAlarmhh.Text & _
                    "', ALARM-H='" & txtAlarmh.Text & _
                    "', ALARM-LLL='" & txtAlarmlll.Text & _
                    "', ALARM-LL='" & txtAlarmll.Text & _
                    "', ALARM-L='" & txtAlarml.Text & _
                    "', PID='" & txtPid.Text & _
                    "', PIDSH='" & txtPidsh.Text & _
                    "', PIDRV='" & txtPidrv.Text & _
                    "', ILD='" & txtIld.Text & _
                    "', ILDSH='" & txtIldsh.Text & _
                    "', ILDRV='" & txtIldrv.Text & _
                    "', LOGIC='" & txtLogic.Text & _
                    "', LOGSH='" & txtLogsh.Text & _
                    "', LOGICRV='" & txtLogicrv.Text & _
                    "', ECD='" & txtEcd.Text & _
                    "', ECDSH='" & txtEcdsh.Text & _
                    "', ECDRV='" & txtEcdrv.Text & _
                    "', JBNO='" & txtJbno.Text & _
                    "', CABLE='" & txtCable.Text & _
                    "', PAIRNO='" & txtPairno.Text & _
                    "', CABLESPECS='" & txtCablespecs.Text & _
                    "', FFSEGNO='" & txtFfsegno.Text & _
                    "', FFLOOPCLASS='" & txtFfloopclass.Text & _
                    "', IIS='" & txtIis.Text & _
                    "', NOTES='" & txtNotes.Text & _
                    "', NOTES1='" & txtNotes1.Text & _
                    "', ILDLOOP='" & txtIldloop.Text & _
                    "', ILD-TAGPOS='" & txtIldtagpos.Text & _
                    "', ILD-STATUS='" & txtIldstatus.Text & _
                    "', MARSHALLING CABINETS='" & txtMCabinets.Text & _
                    "' WHERE ID=" & id & ""

                    cmdSHEDUGM.CommandText = a
                    '"' , REMARKS='" & remarks.Tag & _
                    check = cmdSHEDUGM.ExecuteReader.RecordsAffected

                    MsgBox(a)

                    If check > 0 Then
                        MsgBox("Data With Master Index " & txtMIndex.Text & " Succesfully To Edit", MsgBoxStyle.OkOnly, "Info Update Data")
                    Else
                        MsgBox("Data With Master Index " & txtMIndex.Text & " Failure To Edit", MsgBoxStyle.OkOnly, "Info Update Data")
                    End If

                    'Refresh_Form()
                    conn.Close()

                Catch ex As Exception
                    MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")
                End Try
End If
        End If

    End Sub
 
As Hack said, some help as to what the error is would be useful :) Two inital thoughts :-

1. Having a space in the field name isnt helping - MARSHALLING CABINETS. This will probably want enclosing in square brackets eg [MARSHALLING CABINETS].

2. You really should investigate parameterised queries - see the link in my signature.
 
the error when i try to update is : Error: Microsoft JET Database Engine: Syntax error in UPDATE statement...

when i try to debug it... no records affected....
 
yes most of them are text... id is the only int... and it has a boolean field but i did not include it on the update statement... but im thinking... some fields are still null... so it maybe causing that error.. or not... i also revise the statement.. in which i put an AND instead of comma... that must be one of my error.. but still got the error regarding the statement... i also change the field MARSHALLING CABINETS into MARSHALLINGCABINETS.. but still no luck... my connection to the database is fine... when i select a record,,,
 
Do a debug.write(a) and post what is displayed in the immediate window.

That will tell us what is actually being passed to the databse, and hopefully, point out the syntax error you are getting.
 
since i change my update statement.. my error in exception is : no value given for one or more required parameters... which is i believe the null ones or the remarks field which i didnt include...

here is the error...
UPDATE SHEDUGM SET MASTERINDEX='SH300308' AND SITE='a' AND PLANT='D30' AND TAG='D30-LMBA-3013' AND FLDTAG='' AND DCSTAG='LMBA-3013' AND AUXTAG='' AND CONTAG='' AND FLDSYS='' AND DLSYS='ESD' AND AUXSYS='' AND SERVICE='HPPT D-201; LEVEL HIGH HIGH' AND FUNCTION='BYPASS ALARM' AND EQUIPTAG='' AND OSPAS='' AND IOTYPE='DI' AND SIGNAL='DL' AND POWER='-' AND SOE='' AND IOREDUNDANCY='' AND ENGRANG='-' AND ENGUNIT='-' AND CALRANG='' AND CALUNIT='' AND ALARM-HHH='-' AND ALARM-HH='-' AND ALARM-H='-' AND ALARM-L='-' AND ALARM-LL='-' AND ALARM-LLL='-' AND PID='NA-L87718' AND PIDSH='003' AND PIDRV='' AND ILD='' AND ILDSH='' AND ILDRV='' AND LOGIC='' AND LOGSH='' AND LOGICRV='' AND ECD='' AND ECDSH='' AND ECDRV='' AND JBNO='' AND CABLE='' AND PAIRNO='' AND CABLESPECS='' AND FFSEGNO='' AND FFLOOPCLASS='' AND IIS='' AND NOTES='' AND NOTES1='' AND ILDLOOP='' AND ILD-TAGPOS='' AND ILD-STATUS='' AND MARSHALLINGCABINETS='' WHERE ID=4A first chance exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll

what does it mean?
 
:confused:

You've changed your SQL from a semi-valid syntax into an invalid syntax.

VB.NET:
a = "UPDATE SHEDUGM SET MASTERINDEX='" & txtMIndex.Text & _
                    "', SITE='"

now (I assume) reads

VB.NET:
a = "UPDATE SHEDUGM SET MASTERINDEX='" & txtMIndex.Text & _
                    "' AND SITE='"

You were correct with the comma in the first place. That's probably why you are still receiving errors.
 
if you read my previous post replies.. ive already change it like your suggestions.. but still it has an error... here is the updated code...

im posting the whole code of the form...

VB.NET:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Data.Odbc
Public Class Edit

    Public indexno As Integer
    Public id As Integer
    Public conn As OleDbConnection

    Public Function GetConnect()
        conn = New OleDbConnection
        conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=InstruIO.mdb"

        Return conn
    End Function

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
        'Browse.Show()
    End Sub

    Private Sub Edit_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        indexno = Browse.crow.ToString

        Dim cmdSHEDUGM As New OleDbCommand
        Dim daSHEDUGM As New OleDbDataAdapter
        Dim dsSHEDUGM As New DataSet
        Dim dtSHEDUGM As New DataTable

        conn = GetConnect()

        conn.Open()

        cmdSHEDUGM = conn.CreateCommand
        cmdSHEDUGM.CommandText = "SELECT * FROM SHEDUGM"
        daSHEDUGM.SelectCommand = cmdSHEDUGM
        daSHEDUGM.Fill(dsSHEDUGM, "SHEDUGM")

        id = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("ID").ToString
        txtMIndex.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("MASTERINDEX").ToString
        txtSite.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("SITE").ToString
        txtPlant.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("PLANT").ToString
        txtTag.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("TAG").ToString
        txtFldtag.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("FLDTAG").ToString
        txtDcstag.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("DCSTAG").ToString
        txtAuxtag.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("AUXTAG").ToString
        txtContag.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("CONTAG").ToString
        txtFldsys.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("FLDSYS").ToString
        txtDlsys.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("DLSYS").ToString
        txtAuxsys.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("AUXSYS").ToString
        txtService.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("SERVICE").ToString
        txtFunction.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("FUNCTION").ToString
        txtEquiptag.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("EQUIPTAG").ToString
        txtOspas.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("OSPAS").ToString
        txtIotype.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("IOTYPE").ToString
        txtSignal.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("SIGNAL").ToString
        txtPower.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("POWER").ToString
        txtSoe.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("SOE").ToString
        txtIoredundancy.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("IOREDUNDANCY").ToString
        txtEngrang.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("ENGRANG").ToString
        txtEngunit.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("ENGUNIT").ToString
        txtCalrang.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("CALRANG").ToString
        txtCalunit.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("CALUNIT").ToString
        txtAlarmhhh.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("ALARM-HHH").ToString
        txtAlarmhh.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("ALARM-HH").ToString
        txtAlarmh.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("ALARM-H").ToString
        txtAlarmlll.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("ALARM-LLL").ToString
        txtAlarmll.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("ALARM-LL").ToString
        txtAlarml.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("ALARM-L").ToString
        txtPid.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("PID").ToString
        txtPidsh.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("PIDSH").ToString
        txtPidrv.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("PIDRV").ToString
        txtIld.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("ILD").ToString
        txtIldsh.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("ILDSH").ToString
        txtIldrv.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("ILDRV").ToString
        txtLogic.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("LOGIC").ToString
        txtLogsh.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("LOGSH").ToString
        txtLogicrv.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("LOGICRV").ToString
        txtEcd.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("ECD").ToString
        txtEcdsh.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("ECDSH").ToString
        txtEcdrv.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("ECDRV").ToString
        txtCable.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("CABLE").ToString
        txtPairno.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("PAIRNO").ToString
        txtCablespecs.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("CABLESPECS").ToString
        txtFfsegno.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("FFSEGNO").ToString
        txtFfloopclass.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("FFLOOPCLASS").ToString
        txtIis.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("IIS").ToString
        txtNotes.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("NOTES").ToString
        txtNotes1.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("NOTES1").ToString
        txtIldloop.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("ILDLOOP").ToString
        txtIldtagpos.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("ILD-TAGPOS").ToString
        txtIldstatus.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("ILD-STATUS").ToString
        txtMCabinets.Text = dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("MARSHALLINGCABINETS").ToString

        If dsSHEDUGM.Tables("SHEDUGM").Rows(indexno).Item("REMARKS") = True Then
            remarks.Checked = True
        End If

        conn.Close()

    End Sub

    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim check As Integer
        Dim cmdSHEDUGM As New OleDbCommand
        Dim daSHEDUGM As New OleDbDataAdapter
        Dim dsSHEDUGM As New DataSet
        Dim dtSHEDUGM As New DataTable

        'Edit
        If txtMIndex.Text = "" Then
            MsgBox("Data is not completed", MsgBoxStyle.OkOnly)
        Else
            If MsgBox("Are you sure to edit data with Master Index : " & txtMIndex.Text & " ?", MsgBoxStyle.OkCancel, "Edit confirm") = MsgBoxResult.Cancel Then
                ' do nothing
            Else
                Try
                    conn = GetConnect()
                    conn.Open()
                    cmdSHEDUGM = conn.CreateCommand

                    If remarks.Checked = True Then
                        remarks.Tag = True
                    Else
                        remarks.Tag = False
                    End If

                    Dim a As String

                    a = "UPDATE SHEDUGM SET MASTERINDEX='" & Trim(txtMIndex.Text) & _
                    "' AND SITE='" & txtSite.Text & _
                    "' AND PLANT='" & txtPlant.Text & _
                    "' AND TAG='" & txtTag.Text & _
                    "' AND FLDTAG='" & txtFldtag.Text & _
                    "' AND DCSTAG='" & txtDcstag.Text & _
                    "' AND AUXTAG='" & txtAuxtag.Text & _
                    "' AND CONTAG='" & txtContag.Text & _
                    "' AND FLDSYS='" & txtFldsys.Text & _
                    "' AND DLSYS='" & txtDlsys.Text & _
                    "' AND AUXSYS='" & txtAuxsys.Text & _
                    "' AND SERVICE='" & txtService.Text & _
                    "' AND FUNCTION='" & txtFunction.Text & _
                    "' AND EQUIPTAG='" & txtEquiptag.Text & _
                    "' AND OSPAS='" & txtOspas.Text & _
                    "' AND IOTYPE='" & txtIotype.Text & _
                    "' AND SIGNAL='" & txtSignal.Text & _
                    "' AND POWER='" & txtPower.Text & _
                    "' AND SOE='" & txtSoe.Text & _
                    "' AND IOREDUNDANCY='" & txtIoredundancy.Text & _
                    "' AND ENGRANG='" & txtEngrang.Text & _
                    "' AND ENGUNIT='" & txtEngunit.Text & _
                    "' AND CALRANG='" & txtCalrang.Text & _
                    "' AND CALUNIT='" & txtCalunit.Text & _
                    "' AND ALARM-HHH='" & txtAlarmhhh.Text & _
                    "' AND ALARM-HH='" & txtAlarmhh.Text & _
                    "' AND ALARM-H='" & txtAlarmh.Text & _
                    "' AND ALARM-L='" & txtAlarml.Text & _
                    "' AND ALARM-LL='" & txtAlarmll.Text & _
                    "' AND ALARM-LLL='" & txtAlarmlll.Text & _
                    "' AND PID='" & txtPid.Text & _
                    "' AND PIDSH='" & txtPidsh.Text & _
                    "' AND PIDRV='" & txtPidrv.Text & _
                    "' AND ILD='" & txtIld.Text & _
                    "' AND ILDSH='" & txtIldsh.Text & _
                    "' AND ILDRV='" & txtIldrv.Text & _
                    "' AND LOGIC='" & txtLogic.Text & _
                    "' AND LOGSH='" & txtLogsh.Text & _
                    "' AND LOGICRV='" & txtLogicrv.Text & _
                    "' AND ECD='" & txtEcd.Text & _
                    "' AND ECDSH='" & txtEcdsh.Text & _
                    "' AND ECDRV='" & txtEcdrv.Text & _
                    "' AND JBNO='" & txtJbno.Text & _
                    "' AND CABLE='" & txtCable.Text & _
                    "' AND PAIRNO='" & txtPairno.Text & _
                    "' AND CABLESPECS='" & txtCablespecs.Text & _
                    "' AND FFSEGNO='" & txtFfsegno.Text & _
                    "' AND FFLOOPCLASS='" & txtFfloopclass.Text & _
                    "' AND IIS='" & txtIis.Text & _
                    "' AND NOTES='" & txtNotes.Text & _
                    "' AND NOTES1='" & txtNotes1.Text & _
                    "' AND ILDLOOP='" & txtIldloop.Text & _
                    "' AND ILD-TAGPOS='" & txtIldtagpos.Text & _
                    "' AND ILD-STATUS='" & txtIldstatus.Text & _
                    "' AND MARSHALLINGCABINETS='" & txtMCabinets.Text & _
                    "' WHERE ID=" & id & ""

                    MsgBox(a)
                    Debug.Write(a)

                    cmdSHEDUGM.CommandText = a
                    '"' , REMARKS='" & remarks.Tag & _
                    check = cmdSHEDUGM.ExecuteReader.RecordsAffected

                    If check > 0 Then
                        MsgBox("Data With Master Index " & txtMIndex.Text & " Succesfully To Edit", MsgBoxStyle.OkOnly, "Info Update Data")
                    Else
                        MsgBox("Data With Master Index " & txtMIndex.Text & " Failure To Edit", MsgBoxStyle.OkOnly, "Info Update Data")
                    End If

                    'Refresh_Form()
                    conn.Close()

                Catch ex As Exception
                    MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")
                End Try
            End If
        End If

    End Sub
End Class
 
if you read my previous post replies.. ive already change it like your suggestions

I cant see where anyone suggested you change the commas to AND. You also havent changed to parameters either.
 
Back
Top