Adapter Update...Syntax error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Arne Beruldsen

    #1

    Adapter Update...Syntax error

    I have a simple Access database and I'm using VB.net. I'm getting a syntax
    error on the update line. Any idea what needs to be fixed

    Dim CX As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source= " &
    Application.Sta rtupPath & "\zAdmin.mdb;Us er Id=admin;Passwo rd=;"
    Dim PWConn As New OleDbConnection (CX)

    PWConn.Open()
    SQL = "Select * from Admin"
    Dim AdDataSet As New DataSet
    Dim AdAdapter As New OleDbDataAdapte r(SQL, PWConn)
    AdAdapter.Fill( AdDataSet, "Admin")
    Dim MyCommandBuilde r As New OleDbCommandBui lder(AdAdapter)
    AdAdapter.Inser tCommand = MyCommandBuilde r.GetInsertComm and
    AdAdapter.Updat eCommand = MyCommandBuilde r.GetUpdateComm and
    Dim PwTable As DataTable

    PwTable = AdDataSet.Table s("Admin")
    PwTable.Rows(0) ("Password") = "charlie"
    AdAdapter.Updat e(AdDataSet, "Admin")
    AdDataSet.Accep tChanges()
    PWConn.Close()

    Thanks
  • Ken Tucker [MVP]

    #2
    RE: Adapter Update...Syntax error

    Hi,

    Generally that is caused by a keyword being used a column name for your
    admin table. Surrounding the column name in [ ] will fix the problem. A
    simple fix is to change

    Select * from Admin

    to

    Select [col1], [col2], [col3] from Admin

    Ken
    -------------------------------------

    "Arne Beruldsen" wrote:
    I have a simple Access database and I'm using VB.net. I'm getting a syntax
    error on the update line. Any idea what needs to be fixed
    >
    Dim CX As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source= " &
    Application.Sta rtupPath & "\zAdmin.mdb;Us er Id=admin;Passwo rd=;"
    Dim PWConn As New OleDbConnection (CX)
    >
    PWConn.Open()
    SQL = "Select * from Admin"
    Dim AdDataSet As New DataSet
    Dim AdAdapter As New OleDbDataAdapte r(SQL, PWConn)
    AdAdapter.Fill( AdDataSet, "Admin")
    Dim MyCommandBuilde r As New OleDbCommandBui lder(AdAdapter)
    AdAdapter.Inser tCommand = MyCommandBuilde r.GetInsertComm and
    AdAdapter.Updat eCommand = MyCommandBuilde r.GetUpdateComm and
    Dim PwTable As DataTable
    >
    PwTable = AdDataSet.Table s("Admin")
    PwTable.Rows(0) ("Password") = "charlie"
    AdAdapter.Updat e(AdDataSet, "Admin")
    AdDataSet.Accep tChanges()
    PWConn.Close()
    >
    Thanks

    Comment

    • Arne Beruldsen

      #3
      RE: Adapter Update...Syntax error


      That did it ...thanks...

      "Ken Tucker [MVP]" wrote:
      Hi,
      >
      Generally that is caused by a keyword being used a column name for your
      admin table. Surrounding the column name in [ ] will fix the problem. A
      simple fix is to change
      >
      Select * from Admin
      >
      to
      >
      Select [col1], [col2], [col3] from Admin
      >
      Ken
      -------------------------------------
      >
      "Arne Beruldsen" wrote:
      >
      I have a simple Access database and I'm using VB.net. I'm getting a syntax
      error on the update line. Any idea what needs to be fixed

      Dim CX As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source= " &
      Application.Sta rtupPath & "\zAdmin.mdb;Us er Id=admin;Passwo rd=;"
      Dim PWConn As New OleDbConnection (CX)

      PWConn.Open()
      SQL = "Select * from Admin"
      Dim AdDataSet As New DataSet
      Dim AdAdapter As New OleDbDataAdapte r(SQL, PWConn)
      AdAdapter.Fill( AdDataSet, "Admin")
      Dim MyCommandBuilde r As New OleDbCommandBui lder(AdAdapter)
      AdAdapter.Inser tCommand = MyCommandBuilde r.GetInsertComm and
      AdAdapter.Updat eCommand = MyCommandBuilde r.GetUpdateComm and
      Dim PwTable As DataTable

      PwTable = AdDataSet.Table s("Admin")
      PwTable.Rows(0) ("Password") = "charlie"
      AdAdapter.Updat e(AdDataSet, "Admin")
      AdDataSet.Accep tChanges()
      PWConn.Close()

      Thanks

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: Adapter Update...Syntax error

        Arne,

        Why are you trying to screw up your dataadapter with setting an insert
        command that is already not used because the dynamicly build one in the
        commandbuilder is used?

        Cor

        "Arne Beruldsen" <ArneBeruldsen@ discussions.mic rosoft.comschre ef in
        bericht news:7E1850DF-49C4-4FFC-AF4B-4AE89CF6B6FC@mi crosoft.com...
        >
        That did it ...thanks...
        >
        "Ken Tucker [MVP]" wrote:
        >
        >Hi,
        >>
        > Generally that is caused by a keyword being used a column name for
        >your
        >admin table. Surrounding the column name in [ ] will fix the problem. A
        >simple fix is to change
        >>
        >Select * from Admin
        >>
        >to
        >>
        >Select [col1], [col2], [col3] from Admin
        >>
        >Ken
        >-------------------------------------
        >>
        >"Arne Beruldsen" wrote:
        >>
        I have a simple Access database and I'm using VB.net. I'm getting a
        syntax
        error on the update line. Any idea what needs to be fixed
        >
        Dim CX As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source= " &
        Application.Sta rtupPath & "\zAdmin.mdb;Us er Id=admin;Passwo rd=;"
        Dim PWConn As New OleDbConnection (CX)
        >
        PWConn.Open()
        SQL = "Select * from Admin"
        Dim AdDataSet As New DataSet
        Dim AdAdapter As New OleDbDataAdapte r(SQL, PWConn)
        AdAdapter.Fill( AdDataSet, "Admin")
        Dim MyCommandBuilde r As New OleDbCommandBui lder(AdAdapter)
        AdAdapter.Inser tCommand = MyCommandBuilde r.GetInsertComm and
        AdAdapter.Updat eCommand = MyCommandBuilde r.GetUpdateComm and
        Dim PwTable As DataTable
        >
        PwTable = AdDataSet.Table s("Admin")
        PwTable.Rows(0) ("Password") = "charlie"
        AdAdapter.Updat e(AdDataSet, "Admin")
        AdDataSet.Accep tChanges()
        PWConn.Close()
        >
        Thanks

        Comment

        Working...