Saving changes to a database

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

    #1

    Saving changes to a database

    I'm working on an application using VB .Net 2005 and MS Access 2003 for the
    database. The table I'm trying to update has a key field. When I click the
    Save Button the update seems to work in the dataset, but the database is not
    updated. The code I'm using for the btnSave is:

    Private Sub btnSave_Click(B yVal sender As System.Object, _
    ByVal e As System.EventArg s) Handles btnSave.Click

    'saves adds and edits to database
    If bChange = False Then
    MsgBox("Nothing To Save", MsgBoxStyle.OkO nly, "Test!!!!")
    Else
    Me.Validate()
    Me.TblCompanyBi ndingSource.End Edit()
    Me.TblCompanyTa bleAdapter.Upda te(Me.DsCompDat a.tblCoompany)
    bChange = False
    End If

    Me.DisplayPosit ion() 'reset record location
    Me.setMaintence Buttons(True)

    End Sub

    Any suggestiona dn help is greatly appreciated!!!!

    --
    Tony
  • Cor Ligthert [MVP]

    #2
    Re: Saving changes to a database

    Tony,

    Are you sure that this is your code. Because it seems if you are using two
    different tables.

    Cor

    "Tony A." <TonyA@discussi ons.microsoft.c om> schreef in bericht
    news:E907AFE6-BAE3-4995-92A9-6E330CDC7819@mi crosoft.com...[color=blue]
    > I'm working on an application using VB .Net 2005 and MS Access 2003 for
    > the
    > database. The table I'm trying to update has a key field. When I click
    > the
    > Save Button the update seems to work in the dataset, but the database is
    > not
    > updated. The code I'm using for the btnSave is:
    >
    > Private Sub btnSave_Click(B yVal sender As System.Object, _
    > ByVal e As System.EventArg s) Handles btnSave.Click
    >
    > 'saves adds and edits to database
    > If bChange = False Then
    > MsgBox("Nothing To Save", MsgBoxStyle.OkO nly, "Test!!!!")
    > Else
    > Me.Validate()
    > Me.TblCompanyBi ndingSource.End Edit()
    > Me.TblCompanyTa bleAdapter.Upda te(Me.DsCompDat a.tblCoompany)
    > bChange = False
    > End If
    >
    > Me.DisplayPosit ion() 'reset record location
    > Me.setMaintence Buttons(True)
    >
    > End Sub
    >
    > Any suggestiona dn help is greatly appreciated!!!!
    >
    > --
    > Tony[/color]


    Comment

    • gene kelley

      #3
      Re: Saving changes to a database

      On Tue, 30 May 2006 15:06:01 -0700, Tony A.
      <TonyA@discussi ons.microsoft.c om> wrote:
      [color=blue]
      >I'm working on an application using VB .Net 2005 and MS Access 2003 for the
      >database. The table I'm trying to update has a key field. When I click the
      >Save Button the update seems to work in the dataset, but the database is not
      >updated. The code I'm using for the btnSave is:
      >
      >Private Sub btnSave_Click(B yVal sender As System.Object, _
      > ByVal e As System.EventArg s) Handles btnSave.Click
      >
      > 'saves adds and edits to database
      > If bChange = False Then
      > MsgBox("Nothing To Save", MsgBoxStyle.OkO nly, "Test!!!!")
      > Else
      > Me.Validate()
      > Me.TblCompanyBi ndingSource.End Edit()
      > Me.TblCompanyTa bleAdapter.Upda te(Me.DsCompDat a.tblCoompany)
      > bChange = False
      > End If
      >
      > Me.DisplayPosit ion() 'reset record location
      > Me.setMaintence Buttons(True)
      >
      > End Sub
      >
      >Any suggestiona dn help is greatly appreciated!!!![/color]

      In debug mode? Select the DB and change the "Copy to Output
      Dirirectory" property to something else if it is currently set to
      'Copy Always'

      Gene

      Comment

      • Tony A.

        #4
        Re: Saving changes to a database

        I see where tblCoompany was misspelled. Should have been tblCompany. It is
        correct in the application. Thanks. Other suggestions??
        --
        Tony


        "Cor Ligthert [MVP]" wrote:
        [color=blue]
        > Tony,
        >
        > Are you sure that this is your code. Because it seems if you are using two
        > different tables.
        >
        > Cor
        >
        > "Tony A." <TonyA@discussi ons.microsoft.c om> schreef in bericht
        > news:E907AFE6-BAE3-4995-92A9-6E330CDC7819@mi crosoft.com...[color=green]
        > > I'm working on an application using VB .Net 2005 and MS Access 2003 for
        > > the
        > > database. The table I'm trying to update has a key field. When I click
        > > the
        > > Save Button the update seems to work in the dataset, but the database is
        > > not
        > > updated. The code I'm using for the btnSave is:
        > >
        > > Private Sub btnSave_Click(B yVal sender As System.Object, _
        > > ByVal e As System.EventArg s) Handles btnSave.Click
        > >
        > > 'saves adds and edits to database
        > > If bChange = False Then
        > > MsgBox("Nothing To Save", MsgBoxStyle.OkO nly, "Test!!!!")
        > > Else
        > > Me.Validate()
        > > Me.TblCompanyBi ndingSource.End Edit()
        > > Me.TblCompanyTa bleAdapter.Upda te(Me.DsCompDat a.tblCoompany)
        > > bChange = False
        > > End If
        > >
        > > Me.DisplayPosit ion() 'reset record location
        > > Me.setMaintence Buttons(True)
        > >
        > > End Sub
        > >
        > > Any suggestiona dn help is greatly appreciated!!!!
        > >
        > > --
        > > Tony[/color]
        >
        >
        >[/color]

        Comment

        • ewok66

          #5
          Re: Saving changes to a database

          What is bchange and when is it getting changed? Are you sure the
          tableadapter is firing the update event?
          --
          --ewok
          MCSA+M,MCSE, MCSD, MCDBA,MCITP


          "Tony A." wrote:
          [color=blue]
          > I see where tblCoompany was misspelled. Should have been tblCompany. It is
          > correct in the application. Thanks. Other suggestions??
          > --
          > Tony
          >
          >
          > "Cor Ligthert [MVP]" wrote:
          >[color=green]
          > > Tony,
          > >
          > > Are you sure that this is your code. Because it seems if you are using two
          > > different tables.
          > >
          > > Cor
          > >
          > > "Tony A." <TonyA@discussi ons.microsoft.c om> schreef in bericht
          > > news:E907AFE6-BAE3-4995-92A9-6E330CDC7819@mi crosoft.com...[color=darkred]
          > > > I'm working on an application using VB .Net 2005 and MS Access 2003 for
          > > > the
          > > > database. The table I'm trying to update has a key field. When I click
          > > > the
          > > > Save Button the update seems to work in the dataset, but the database is
          > > > not
          > > > updated. The code I'm using for the btnSave is:
          > > >
          > > > Private Sub btnSave_Click(B yVal sender As System.Object, _
          > > > ByVal e As System.EventArg s) Handles btnSave.Click
          > > >
          > > > 'saves adds and edits to database
          > > > If bChange = False Then
          > > > MsgBox("Nothing To Save", MsgBoxStyle.OkO nly, "Test!!!!")
          > > > Else
          > > > Me.Validate()
          > > > Me.TblCompanyBi ndingSource.End Edit()
          > > > Me.TblCompanyTa bleAdapter.Upda te(Me.DsCompDat a.tblCoompany)
          > > > bChange = False
          > > > End If
          > > >
          > > > Me.DisplayPosit ion() 'reset record location
          > > > Me.setMaintence Buttons(True)
          > > >
          > > > End Sub
          > > >
          > > > Any suggestiona dn help is greatly appreciated!!!!
          > > >
          > > > --
          > > > Tony[/color]
          > >
          > >
          > >[/color][/color]

          Comment

          • Tony A.

            #6
            Re: Saving changes to a database

            I have a procedure that checks to see if the value in any of the text boxes
            or combo box has changed = bchange

            The program crashes at the TableAdapter.Up date line. This error appears:

            Update requires a valid UpdateCommand when passed DataRow collection with
            modified rows.


            --
            Tony


            "ewok66" wrote:
            [color=blue]
            > What is bchange and when is it getting changed? Are you sure the
            > tableadapter is firing the update event?
            > --
            > --ewok
            > MCSA+M,MCSE, MCSD, MCDBA,MCITP
            >
            >
            > "Tony A." wrote:
            >[color=green]
            > > I see where tblCoompany was misspelled. Should have been tblCompany. It is
            > > correct in the application. Thanks. Other suggestions??
            > > --
            > > Tony
            > >
            > >
            > > "Cor Ligthert [MVP]" wrote:
            > >[color=darkred]
            > > > Tony,
            > > >
            > > > Are you sure that this is your code. Because it seems if you are using two
            > > > different tables.
            > > >
            > > > Cor
            > > >
            > > > "Tony A." <TonyA@discussi ons.microsoft.c om> schreef in bericht
            > > > news:E907AFE6-BAE3-4995-92A9-6E330CDC7819@mi crosoft.com...
            > > > > I'm working on an application using VB .Net 2005 and MS Access 2003 for
            > > > > the
            > > > > database. The table I'm trying to update has a key field. When I click
            > > > > the
            > > > > Save Button the update seems to work in the dataset, but the database is
            > > > > not
            > > > > updated. The code I'm using for the btnSave is:
            > > > >
            > > > > Private Sub btnSave_Click(B yVal sender As System.Object, _
            > > > > ByVal e As System.EventArg s) Handles btnSave.Click
            > > > >
            > > > > 'saves adds and edits to database
            > > > > If bChange = False Then
            > > > > MsgBox("Nothing To Save", MsgBoxStyle.OkO nly, "Test!!!!")
            > > > > Else
            > > > > Me.Validate()
            > > > > Me.TblCompanyBi ndingSource.End Edit()
            > > > > Me.TblCompanyTa bleAdapter.Upda te(Me.DsCompDat a.tblCoompany)
            > > > > bChange = False
            > > > > End If
            > > > >
            > > > > Me.DisplayPosit ion() 'reset record location
            > > > > Me.setMaintence Buttons(True)
            > > > >
            > > > > End Sub
            > > > >
            > > > > Any suggestiona dn help is greatly appreciated!!!!
            > > > >
            > > > > --
            > > > > Tony
            > > >
            > > >
            > > >[/color][/color][/color]

            Comment

            • ewok66

              #7
              Re: Saving changes to a database

              Sounds like you need an update statement - did you remove it at some point
              from your data adapter? If you use a wizard to automatically add one, ensure
              part of the update statement doesn't try and update your key field.
              --
              --ewok
              MCSA+M,MCSE, MCSD, MCDBA,MCITP


              "Tony A." wrote:
              [color=blue]
              > I have a procedure that checks to see if the value in any of the text boxes
              > or combo box has changed = bchange
              >
              > The program crashes at the TableAdapter.Up date line. This error appears:
              >
              > Update requires a valid UpdateCommand when passed DataRow collection with
              > modified rows.
              >
              >
              > --
              > Tony
              >
              >
              > "ewok66" wrote:
              >[color=green]
              > > What is bchange and when is it getting changed? Are you sure the
              > > tableadapter is firing the update event?
              > > --
              > > --ewok
              > > MCSA+M,MCSE, MCSD, MCDBA,MCITP
              > >
              > >
              > > "Tony A." wrote:
              > >[color=darkred]
              > > > I see where tblCoompany was misspelled. Should have been tblCompany. It is
              > > > correct in the application. Thanks. Other suggestions??
              > > > --
              > > > Tony
              > > >
              > > >
              > > > "Cor Ligthert [MVP]" wrote:
              > > >
              > > > > Tony,
              > > > >
              > > > > Are you sure that this is your code. Because it seems if you are using two
              > > > > different tables.
              > > > >
              > > > > Cor
              > > > >
              > > > > "Tony A." <TonyA@discussi ons.microsoft.c om> schreef in bericht
              > > > > news:E907AFE6-BAE3-4995-92A9-6E330CDC7819@mi crosoft.com...
              > > > > > I'm working on an application using VB .Net 2005 and MS Access 2003 for
              > > > > > the
              > > > > > database. The table I'm trying to update has a key field. When I click
              > > > > > the
              > > > > > Save Button the update seems to work in the dataset, but the database is
              > > > > > not
              > > > > > updated. The code I'm using for the btnSave is:
              > > > > >
              > > > > > Private Sub btnSave_Click(B yVal sender As System.Object, _
              > > > > > ByVal e As System.EventArg s) Handles btnSave.Click
              > > > > >
              > > > > > 'saves adds and edits to database
              > > > > > If bChange = False Then
              > > > > > MsgBox("Nothing To Save", MsgBoxStyle.OkO nly, "Test!!!!")
              > > > > > Else
              > > > > > Me.Validate()
              > > > > > Me.TblCompanyBi ndingSource.End Edit()
              > > > > > Me.TblCompanyTa bleAdapter.Upda te(Me.DsCompDat a.tblCoompany)
              > > > > > bChange = False
              > > > > > End If
              > > > > >
              > > > > > Me.DisplayPosit ion() 'reset record location
              > > > > > Me.setMaintence Buttons(True)
              > > > > >
              > > > > > End Sub
              > > > > >
              > > > > > Any suggestiona dn help is greatly appreciated!!!!
              > > > > >
              > > > > > --
              > > > > > Tony
              > > > >
              > > > >
              > > > >[/color][/color][/color]

              Comment

              • Tony A.

                #8
                Re: Saving changes to a database

                Thank you.
                --
                Tony


                "ewok66" wrote:
                [color=blue]
                > Sounds like you need an update statement - did you remove it at some point
                > from your data adapter? If you use a wizard to automatically add one, ensure
                > part of the update statement doesn't try and update your key field.
                > --
                > --ewok
                > MCSA+M,MCSE, MCSD, MCDBA,MCITP
                >
                >
                > "Tony A." wrote:
                >[color=green]
                > > I have a procedure that checks to see if the value in any of the text boxes
                > > or combo box has changed = bchange
                > >
                > > The program crashes at the TableAdapter.Up date line. This error appears:
                > >
                > > Update requires a valid UpdateCommand when passed DataRow collection with
                > > modified rows.
                > >
                > >
                > > --
                > > Tony
                > >
                > >
                > > "ewok66" wrote:
                > >[color=darkred]
                > > > What is bchange and when is it getting changed? Are you sure the
                > > > tableadapter is firing the update event?
                > > > --
                > > > --ewok
                > > > MCSA+M,MCSE, MCSD, MCDBA,MCITP
                > > >
                > > >
                > > > "Tony A." wrote:
                > > >
                > > > > I see where tblCoompany was misspelled. Should have been tblCompany. It is
                > > > > correct in the application. Thanks. Other suggestions??
                > > > > --
                > > > > Tony
                > > > >
                > > > >
                > > > > "Cor Ligthert [MVP]" wrote:
                > > > >
                > > > > > Tony,
                > > > > >
                > > > > > Are you sure that this is your code. Because it seems if you are using two
                > > > > > different tables.
                > > > > >
                > > > > > Cor
                > > > > >
                > > > > > "Tony A." <TonyA@discussi ons.microsoft.c om> schreef in bericht
                > > > > > news:E907AFE6-BAE3-4995-92A9-6E330CDC7819@mi crosoft.com...
                > > > > > > I'm working on an application using VB .Net 2005 and MS Access 2003 for
                > > > > > > the
                > > > > > > database. The table I'm trying to update has a key field. When I click
                > > > > > > the
                > > > > > > Save Button the update seems to work in the dataset, but the database is
                > > > > > > not
                > > > > > > updated. The code I'm using for the btnSave is:
                > > > > > >
                > > > > > > Private Sub btnSave_Click(B yVal sender As System.Object, _
                > > > > > > ByVal e As System.EventArg s) Handles btnSave.Click
                > > > > > >
                > > > > > > 'saves adds and edits to database
                > > > > > > If bChange = False Then
                > > > > > > MsgBox("Nothing To Save", MsgBoxStyle.OkO nly, "Test!!!!")
                > > > > > > Else
                > > > > > > Me.Validate()
                > > > > > > Me.TblCompanyBi ndingSource.End Edit()
                > > > > > > Me.TblCompanyTa bleAdapter.Upda te(Me.DsCompDat a.tblCoompany)
                > > > > > > bChange = False
                > > > > > > End If
                > > > > > >
                > > > > > > Me.DisplayPosit ion() 'reset record location
                > > > > > > Me.setMaintence Buttons(True)
                > > > > > >
                > > > > > > End Sub
                > > > > > >
                > > > > > > Any suggestiona dn help is greatly appreciated!!!!
                > > > > > >
                > > > > > > --
                > > > > > > Tony
                > > > > >
                > > > > >
                > > > > >[/color][/color][/color]

                Comment

                Working...