ADO Update Problem

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

    #1

    ADO Update Problem

    Hi,

    We have a process management system in VB .NET. It usually used text
    files, but I'm trying to switch to using access database files and
    ADO.

    I made a form with a datagrid and a few buttons.

    I define the variables for this program as follows:

    Imports System.Data.Ole Db

    Private dbConnRoutine As OleDbConnection = Nothing
    Private dbAdapterRoutin e As OleDbDataAdapte r = Nothing
    Private dbDataSetRoutin e As DataSet = Nothing
    Private dbBuilderRoutin e As OleDbCommandBui lder = Nothing

    When they press the LOAD button, the following is executed:

    Dim connString As String
    Dim sql As String


    connString = "Provider=Micro soft.Jet.OLEDB. 4.0; Data
    Source=" + FileName
    dbConnRoutine = New OleDbConnection (connString)

    sql = "SELECT * FROM rtnmain"
    Dim objCommand As New OleDbCommand(sq l, dbConnRoutine)

    dbAdapterRoutin e = New OleDbDataAdapte r(objCommand)
    dbAdapterRoutin e.TableMappings .Add("Table", "rtnmain")
    dbBuilderRoutin e = New
    OleDbCommandBui lder(dbAdapterR outine)

    dbDataSetRoutin e = New DataSet("rtnmai n")

    dbAdapterRoutin e.Fill(dbDataSe tRoutine, "rtnmain")
    gridRoutine.Dat aSource =
    dbDataSetRoutin e.Tables("rtnma in")
    gridRoutine.Set DataBinding(dbD ataSetRoutine,
    "rtnmain")


    At which point, the data is loaded. No problems there.

    Then, I'll add a row to the datagrid. I press the UPDATE button. The
    following code is executed:

    dbBuilderRoutin e.GetUpdateComm and()
    dbAdapterRoutin e.Update(dbData SetRoutine)

    The result is an error.

    An unhandled exception of type 'System.NullRef erenceException '
    occurred in system.data.dll

    Additional information: Object reference not set to an instance
    of an object.

    Every example I've checked follows this process. Can anyone point out
    what I'm doing wrong, or perhaps an alternative way of updating the
    table?

    Another question:: do I have to re-fill the dataset before trying to
    update?

    Thanks!
    Tom Junior
  • Cor Ligthert[MVP]

    #2
    Re: ADO Update Problem

    Hi,

    I don't see real errors however not needed in your code is
    - the setting to nothing,
    - dbBuilderRoutin e.GetUpdateComm and()
    (The latter can be the reason of your error, I have never used that.)

    Cor


    "TBass" <tbj@automatedd esign.comschree f in bericht
    news:f3773ac6-3dc0-4d6a-b467-0a39144129f2@e2 3g2000prf.googl egroups.com...
    Hi,
    >
    We have a process management system in VB .NET. It usually used text
    files, but I'm trying to switch to using access database files and
    ADO.
    >
    I made a form with a datagrid and a few buttons.
    >
    I define the variables for this program as follows:
    >
    Imports System.Data.Ole Db
    >
    Private dbConnRoutine As OleDbConnection = Nothing
    Private dbAdapterRoutin e As OleDbDataAdapte r = Nothing
    Private dbDataSetRoutin e As DataSet = Nothing
    Private dbBuilderRoutin e As OleDbCommandBui lder = Nothing
    >
    When they press the LOAD button, the following is executed:
    >
    Dim connString As String
    Dim sql As String
    >
    >
    connString = "Provider=Micro soft.Jet.OLEDB. 4.0; Data
    Source=" + FileName
    dbConnRoutine = New OleDbConnection (connString)
    >
    sql = "SELECT * FROM rtnmain"
    Dim objCommand As New OleDbCommand(sq l, dbConnRoutine)
    >
    dbAdapterRoutin e = New OleDbDataAdapte r(objCommand)
    dbAdapterRoutin e.TableMappings .Add("Table", "rtnmain")
    dbBuilderRoutin e = New
    OleDbCommandBui lder(dbAdapterR outine)
    >
    dbDataSetRoutin e = New DataSet("rtnmai n")
    >
    dbAdapterRoutin e.Fill(dbDataSe tRoutine, "rtnmain")
    gridRoutine.Dat aSource =
    dbDataSetRoutin e.Tables("rtnma in")
    gridRoutine.Set DataBinding(dbD ataSetRoutine,
    "rtnmain")
    >
    >
    At which point, the data is loaded. No problems there.
    >
    Then, I'll add a row to the datagrid. I press the UPDATE button. The
    following code is executed:
    >
    dbBuilderRoutin e.GetUpdateComm and()
    dbAdapterRoutin e.Update(dbData SetRoutine)
    >
    The result is an error.
    >
    An unhandled exception of type 'System.NullRef erenceException '
    occurred in system.data.dll
    >
    Additional information: Object reference not set to an instance
    of an object.
    >
    Every example I've checked follows this process. Can anyone point out
    what I'm doing wrong, or perhaps an alternative way of updating the
    table?
    >
    Another question:: do I have to re-fill the dataset before trying to
    update?
    >
    Thanks!
    Tom Junior

    Comment

    • TBass

      #3
      Re: ADO Update Problem

      On Dec 17, 12:21 am, "Cor Ligthert[MVP]" <notmyfirstn... @planet.nl>
      wrote:
      Hi,
      >
      I don't see real errors however not needed in your code is
      - the setting to nothing,
      - dbBuilderRoutin e.GetUpdateComm and()
      (The latter can be the reason of your error, I have never used that.)
      >
      Cor
      >
      "TBass" <t...@automated design.comschre ef in berichtnews:f37 73ac6-3dc0-4d6a-b467-0a39144129f2@e2 3g2000prf.googl egroups.com...
      >
      >
      >
      Hi,
      >
      We have a process management system in VB .NET. It usually used text
      files, but I'm trying to switch to using access database files and
      ADO.
      >
      I made a form with a datagrid and a few buttons.
      >
      I define the variables for this program as follows:
      >
      Imports System.Data.Ole Db
      >
      Private dbConnRoutine As OleDbConnection = Nothing
      Private dbAdapterRoutin e As OleDbDataAdapte r = Nothing
      Private dbDataSetRoutin e As DataSet = Nothing
      Private dbBuilderRoutin e As OleDbCommandBui lder = Nothing
      >
      When they press the LOAD button, the following is executed:
      >
      Dim connString As String
      Dim sql As String
      >
      connString = "Provider=Micro soft.Jet.OLEDB. 4.0; Data
      Source=" + FileName
      dbConnRoutine = New OleDbConnection (connString)
      >
      sql = "SELECT * FROM rtnmain"
      Dim objCommand As New OleDbCommand(sq l, dbConnRoutine)
      >
      dbAdapterRoutin e = New OleDbDataAdapte r(objCommand)
      dbAdapterRoutin e.TableMappings .Add("Table", "rtnmain")
      dbBuilderRoutin e = New
      OleDbCommandBui lder(dbAdapterR outine)
      >
      dbDataSetRoutin e = New DataSet("rtnmai n")
      >
      dbAdapterRoutin e.Fill(dbDataSe tRoutine, "rtnmain")
      gridRoutine.Dat aSource =
      dbDataSetRoutin e.Tables("rtnma in")
      gridRoutine.Set DataBinding(dbD ataSetRoutine,
      "rtnmain")
      >
      At which point, the data is loaded. No problems there.
      >
      Then, I'll add a row to the datagrid. I press the UPDATE button. The
      following code is executed:
      >
      dbBuilderRoutin e.GetUpdateComm and()
      dbAdapterRoutin e.Update(dbData SetRoutine)
      >
      The result is an error.
      >
      An unhandled exception of type 'System.NullRef erenceException '
      occurred in system.data.dll
      >
      Additional information: Object reference not set to an instance
      of an object.
      >
      Every example I've checked follows this process. Can anyone point out
      what I'm doing wrong, or perhaps an alternative way of updating the
      table?
      >
      Another question:: do I have to re-fill the dataset before trying to
      update?
      >
      Thanks!
      Tom Junior- Hide quoted text -
      >
      - Show quoted text -
      Neither of those changes solved the problem. In the end, I had to go
      with a rather complicated solution where I wrote a seperate class to
      deal with the database interaction, and I set the datagrid to read
      only, using buttons and forms for adding/editing rows. That has worked
      flawlessly.

      Thanks for the feedback.
      T

      Comment

      Working...