Home All Groups Group Topic Archive Search About

Problem Adding new record to a database

Author
20 Sep 2006 8:38 PM
Tony A.
I'm using VB .Net 2005 with Access 2003 for the database.  The database has
two tables:  tblContact (ContactNum (k), lastname, firstname, phone, email,
compNum) and tblCompany (CompNun (k), CompName, address, city, state, zip,
compNum)

There are a unumber of contact at each company.  I have created a Windows
form where I can select a contact, all of the information about the contact
(tblContact), and the information about the (tblCompany) appears and can be
edited.

If I try to add a new contact, at a new company; the contact information is
saved to tblContact, but the company is not saved.  Edit can be made to any
field for either table, but new records cannot be added to the company table.

The code is:

Private Sub TblContactBindingNavigatorSaveItem_Click(ByVal sender _
    As System.Object, ByVal e As System.EventArgs) _
    Handles TblContactsBindingNavigatorSaveItem.Click
        'save, update records
        Me.Validate()
        Me.TblCompanyBindingSource.EndEdit()
        Me.TblCompanyTableAdapter.Update(Me.DsContactData.tblCoAddress)

        Me.TblContactBindingSource.EndEdit()
        Me.TblContactTableAdapter.Update(Me.DsContactData.tblContact)
    End Sub

When I run the program no errors appear, but nothing is saved to the
tblCompany table. Any help will be appreciated.

--
Tony

Author
20 Sep 2006 9:16 PM
Izzy
Honestly I would not use Adapter.Update() to write your update, insert
and delete statements for you. In my opinion that's kind of a lazy way
to write programs.

My solution to this is to use the Oledb.Command object and write insert
and update statements yourself. When the user adds a new company, run
the insert, then let them add new contacts for that company once the
database has returned the Primary Key for the Company.

Izzy


Tony A. wrote:
Show quoteHide quote
> I'm using VB .Net 2005 with Access 2003 for the database.  The database has
> two tables:  tblContact (ContactNum (k), lastname, firstname, phone, email,
> compNum) and tblCompany (CompNun (k), CompName, address, city, state, zip,
> compNum)
>
> There are a unumber of contact at each company.  I have created a Windows
> form where I can select a contact, all of the information about the contact
> (tblContact), and the information about the (tblCompany) appears and can be
> edited.
>
> If I try to add a new contact, at a new company; the contact information is
> saved to tblContact, but the company is not saved.  Edit can be made to any
> field for either table, but new records cannot be added to the company table.
>
> The code is:
>
> Private Sub TblContactBindingNavigatorSaveItem_Click(ByVal sender _
>     As System.Object, ByVal e As System.EventArgs) _
>     Handles TblContactsBindingNavigatorSaveItem.Click
>         'save, update records
>         Me.Validate()
>         Me.TblCompanyBindingSource.EndEdit()
>         Me.TblCompanyTableAdapter.Update(Me.DsContactData.tblCoAddress)
>
>         Me.TblContactBindingSource.EndEdit()
>         Me.TblContactTableAdapter.Update(Me.DsContactData.tblContact)
>     End Sub
>
> When I run the program no errors appear, but nothing is saved to the
> tblCompany table. Any help will be appreciated.
>
> --
> Tony
Author
20 Sep 2006 11:10 PM
Tony A.
Thanks Izzy, I was looking for the lazy way out, but if it's not going to
work I'll have to do things the right way.
--
Tony


Show quoteHide quote
"Izzy" wrote:

> Honestly I would not use Adapter.Update() to write your update, insert
> and delete statements for you. In my opinion that's kind of a lazy way
> to write programs.
>
> My solution to this is to use the Oledb.Command object and write insert
> and update statements yourself. When the user adds a new company, run
> the insert, then let them add new contacts for that company once the
> database has returned the Primary Key for the Company.
>
> Izzy
>
>
> Tony A. wrote:
> > I'm using VB .Net 2005 with Access 2003 for the database.  The database has
> > two tables:  tblContact (ContactNum (k), lastname, firstname, phone, email,
> > compNum) and tblCompany (CompNun (k), CompName, address, city, state, zip,
> > compNum)
> >
> > There are a unumber of contact at each company.  I have created a Windows
> > form where I can select a contact, all of the information about the contact
> > (tblContact), and the information about the (tblCompany) appears and can be
> > edited.
> >
> > If I try to add a new contact, at a new company; the contact information is
> > saved to tblContact, but the company is not saved.  Edit can be made to any
> > field for either table, but new records cannot be added to the company table.
> >
> > The code is:
> >
> > Private Sub TblContactBindingNavigatorSaveItem_Click(ByVal sender _
> >     As System.Object, ByVal e As System.EventArgs) _
> >     Handles TblContactsBindingNavigatorSaveItem.Click
> >         'save, update records
> >         Me.Validate()
> >         Me.TblCompanyBindingSource.EndEdit()
> >         Me.TblCompanyTableAdapter.Update(Me.DsContactData.tblCoAddress)
> >
> >         Me.TblContactBindingSource.EndEdit()
> >         Me.TblContactTableAdapter.Update(Me.DsContactData.tblContact)
> >     End Sub
> >
> > When I run the program no errors appear, but nothing is saved to the
> > tblCompany table. Any help will be appreciated.
> >
> > --
> > Tony
>
>
Author
21 Sep 2006 4:53 AM
Cor Ligthert [MVP]
Tony,

You say it is not added, is there not any error?
(Because than there are most probably changes done in the row)

Cor

Show quoteHide quote
"Tony A." <To***@discussions.microsoft.com> schreef in bericht
news:D16269CD-73E5-4B3E-B5D8-C44BFB3C48E6@microsoft.com...
> Thanks Izzy, I was looking for the lazy way out, but if it's not going to
> work I'll have to do things the right way.
> --
> Tony
>
>
> "Izzy" wrote:
>
>> Honestly I would not use Adapter.Update() to write your update, insert
>> and delete statements for you. In my opinion that's kind of a lazy way
>> to write programs.
>>
>> My solution to this is to use the Oledb.Command object and write insert
>> and update statements yourself. When the user adds a new company, run
>> the insert, then let them add new contacts for that company once the
>> database has returned the Primary Key for the Company.
>>
>> Izzy
>>
>>
>> Tony A. wrote:
>> > I'm using VB .Net 2005 with Access 2003 for the database.  The database
>> > has
>> > two tables:  tblContact (ContactNum (k), lastname, firstname, phone,
>> > email,
>> > compNum) and tblCompany (CompNun (k), CompName, address, city, state,
>> > zip,
>> > compNum)
>> >
>> > There are a unumber of contact at each company.  I have created a
>> > Windows
>> > form where I can select a contact, all of the information about the
>> > contact
>> > (tblContact), and the information about the (tblCompany) appears and
>> > can be
>> > edited.
>> >
>> > If I try to add a new contact, at a new company; the contact
>> > information is
>> > saved to tblContact, but the company is not saved.  Edit can be made to
>> > any
>> > field for either table, but new records cannot be added to the company
>> > table.
>> >
>> > The code is:
>> >
>> > Private Sub TblContactBindingNavigatorSaveItem_Click(ByVal sender _
>> >     As System.Object, ByVal e As System.EventArgs) _
>> >     Handles TblContactsBindingNavigatorSaveItem.Click
>> >         'save, update records
>> >         Me.Validate()
>> >         Me.TblCompanyBindingSource.EndEdit()
>> >         Me.TblCompanyTableAdapter.Update(Me.DsContactData.tblCoAddress)
>> >
>> >         Me.TblContactBindingSource.EndEdit()
>> >         Me.TblContactTableAdapter.Update(Me.DsContactData.tblContact)
>> >     End Sub
>> >
>> > When I run the program no errors appear, but nothing is saved to the
>> > tblCompany table. Any help will be appreciated.
>> >
>> > --
>> > Tony
>>
>>
Author
21 Sep 2006 4:16 PM
Tony A.
You are correct, there are no error messages.  When I open the database the
contact table has the new record added, but the company does not.  I have
switched between having the company table updated first then the contact
table, and vise versa.
--
Tony


Show quoteHide quote
"Cor Ligthert [MVP]" wrote:

> Tony,
>
> You say it is not added, is there not any error?
> (Because than there are most probably changes done in the row)
>
> Cor
>
> "Tony A." <To***@discussions.microsoft.com> schreef in bericht
> news:D16269CD-73E5-4B3E-B5D8-C44BFB3C48E6@microsoft.com...
> > Thanks Izzy, I was looking for the lazy way out, but if it's not going to
> > work I'll have to do things the right way.
> > --
> > Tony
> >
> >
> > "Izzy" wrote:
> >
> >> Honestly I would not use Adapter.Update() to write your update, insert
> >> and delete statements for you. In my opinion that's kind of a lazy way
> >> to write programs.
> >>
> >> My solution to this is to use the Oledb.Command object and write insert
> >> and update statements yourself. When the user adds a new company, run
> >> the insert, then let them add new contacts for that company once the
> >> database has returned the Primary Key for the Company.
> >>
> >> Izzy
> >>
> >>
> >> Tony A. wrote:
> >> > I'm using VB .Net 2005 with Access 2003 for the database.  The database
> >> > has
> >> > two tables:  tblContact (ContactNum (k), lastname, firstname, phone,
> >> > email,
> >> > compNum) and tblCompany (CompNun (k), CompName, address, city, state,
> >> > zip,
> >> > compNum)
> >> >
> >> > There are a unumber of contact at each company.  I have created a
> >> > Windows
> >> > form where I can select a contact, all of the information about the
> >> > contact
> >> > (tblContact), and the information about the (tblCompany) appears and
> >> > can be
> >> > edited.
> >> >
> >> > If I try to add a new contact, at a new company; the contact
> >> > information is
> >> > saved to tblContact, but the company is not saved.  Edit can be made to
> >> > any
> >> > field for either table, but new records cannot be added to the company
> >> > table.
> >> >
> >> > The code is:
> >> >
> >> > Private Sub TblContactBindingNavigatorSaveItem_Click(ByVal sender _
> >> >     As System.Object, ByVal e As System.EventArgs) _
> >> >     Handles TblContactsBindingNavigatorSaveItem.Click
> >> >         'save, update records
> >> >         Me.Validate()
> >> >         Me.TblCompanyBindingSource.EndEdit()
> >> >         Me.TblCompanyTableAdapter.Update(Me.DsContactData.tblCoAddress)
> >> >
> >> >         Me.TblContactBindingSource.EndEdit()
> >> >         Me.TblContactTableAdapter.Update(Me.DsContactData.tblContact)
> >> >     End Sub
> >> >
> >> > When I run the program no errors appear, but nothing is saved to the
> >> > tblCompany table. Any help will be appreciated.
> >> >
> >> > --
> >> > Tony
> >>
> >>
>
>
>
Author
22 Sep 2006 5:14 AM
Cor Ligthert [MVP]
Than you have to check if the rows have really changes before the update.

If dt.haschanges then

or whatever like that.

Cor

Show quoteHide quote
"Tony A." <To***@discussions.microsoft.com> schreef in bericht
news:8B93EB3B-22FA-4F92-887E-0C9A329621CB@microsoft.com...
> You are correct, there are no error messages.  When I open the database
> the
> contact table has the new record added, but the company does not.  I have
> switched between having the company table updated first then the contact
> table, and vise versa.
> --
> Tony
>
>
> "Cor Ligthert [MVP]" wrote:
>
>> Tony,
>>
>> You say it is not added, is there not any error?
>> (Because than there are most probably changes done in the row)
>>
>> Cor
>>
>> "Tony A." <To***@discussions.microsoft.com> schreef in bericht
>> news:D16269CD-73E5-4B3E-B5D8-C44BFB3C48E6@microsoft.com...
>> > Thanks Izzy, I was looking for the lazy way out, but if it's not going
>> > to
>> > work I'll have to do things the right way.
>> > --
>> > Tony
>> >
>> >
>> > "Izzy" wrote:
>> >
>> >> Honestly I would not use Adapter.Update() to write your update, insert
>> >> and delete statements for you. In my opinion that's kind of a lazy way
>> >> to write programs.
>> >>
>> >> My solution to this is to use the Oledb.Command object and write
>> >> insert
>> >> and update statements yourself. When the user adds a new company, run
>> >> the insert, then let them add new contacts for that company once the
>> >> database has returned the Primary Key for the Company.
>> >>
>> >> Izzy
>> >>
>> >>
>> >> Tony A. wrote:
>> >> > I'm using VB .Net 2005 with Access 2003 for the database.  The
>> >> > database
>> >> > has
>> >> > two tables:  tblContact (ContactNum (k), lastname, firstname, phone,
>> >> > email,
>> >> > compNum) and tblCompany (CompNun (k), CompName, address, city,
>> >> > state,
>> >> > zip,
>> >> > compNum)
>> >> >
>> >> > There are a unumber of contact at each company.  I have created a
>> >> > Windows
>> >> > form where I can select a contact, all of the information about the
>> >> > contact
>> >> > (tblContact), and the information about the (tblCompany) appears and
>> >> > can be
>> >> > edited.
>> >> >
>> >> > If I try to add a new contact, at a new company; the contact
>> >> > information is
>> >> > saved to tblContact, but the company is not saved.  Edit can be made
>> >> > to
>> >> > any
>> >> > field for either table, but new records cannot be added to the
>> >> > company
>> >> > table.
>> >> >
>> >> > The code is:
>> >> >
>> >> > Private Sub TblContactBindingNavigatorSaveItem_Click(ByVal sender _
>> >> >     As System.Object, ByVal e As System.EventArgs) _
>> >> >     Handles TblContactsBindingNavigatorSaveItem.Click
>> >> >         'save, update records
>> >> >         Me.Validate()
>> >> >         Me.TblCompanyBindingSource.EndEdit()
>> >> >
>> >> > Me.TblCompanyTableAdapter.Update(Me.DsContactData.tblCoAddress)
>> >> >
>> >> >         Me.TblContactBindingSource.EndEdit()
>> >> >
>> >> > Me.TblContactTableAdapter.Update(Me.DsContactData.tblContact)
>> >> >     End Sub
>> >> >
>> >> > When I run the program no errors appear, but nothing is saved to the
>> >> > tblCompany table. Any help will be appreciated.
>> >> >
>> >> > --
>> >> > Tony
>> >>
>> >>
>>
>>
>>
Author
21 Sep 2006 9:11 AM
gene kelley
On Wed, 20 Sep 2006 13:38:02 -0700, Tony A. <To***@discussions.microsoft.com> wrote:

Show quoteHide quote
>I'm using VB .Net 2005 with Access 2003 for the database.  The database has
>two tables:  tblContact (ContactNum (k), lastname, firstname, phone, email,
>compNum) and tblCompany (CompNun (k), CompName, address, city, state, zip,
>compNum)
>
>There are a unumber of contact at each company.  I have created a Windows
>form where I can select a contact, all of the information about the contact
>(tblContact), and the information about the (tblCompany) appears and can be
>edited.
>
>If I try to add a new contact, at a new company; the contact information is
>saved to tblContact, but the company is not saved.  Edit can be made to any
>field for either table, but new records cannot be added to the company table.
>
>The code is:
>
>Private Sub TblContactBindingNavigatorSaveItem_Click(ByVal sender _
>    As System.Object, ByVal e As System.EventArgs) _
>    Handles TblContactsBindingNavigatorSaveItem.Click
>        'save, update records
>        Me.Validate()
>        Me.TblCompanyBindingSource.EndEdit()
>        Me.TblCompanyTableAdapter.Update(Me.DsContactData.tblCoAddress)
>
>        Me.TblContactBindingSource.EndEdit()
>        Me.TblContactTableAdapter.Update(Me.DsContactData.tblContact)
>    End Sub
>
>When I run the program no errors appear, but nothing is saved to the
>tblCompany table. Any help will be appreciated.

Build a release.  Run the release executable, make some changes and then exit. Rerun
the release executable and see if the changes are shown.

Gene
Author
21 Sep 2006 7:03 PM
kgerritsen
Tony,

Two ideas:  First, is there any referential integrity defined in the
Access database on the foreign key CompNum?  If so, I'd actually expect
the reverse (no new contact insert until the company was inserted), but
I have experienced Access get the integrity relationship backwards once
before.

When using table adapter update, I've been more successful with
extracting a changed dataset as in the following approach:
                Dim dschg As DataSet
                dschg = ds.GetChanges()

                If Not dschg Is Nothing Then
                    da.Update(dschg, SqlTable)
                End If

Actually, a third idea: make sure there are no nulls or type-illegal
data in the tblCompany rows.

Regards,
Keith

Tony A. wrote:
Show quoteHide quote
> I'm using VB .Net 2005 with Access 2003 for the database.  The database has
> two tables:  tblContact (ContactNum (k), lastname, firstname, phone, email,
> compNum) and tblCompany (CompNun (k), CompName, address, city, state, zip,
> compNum)
>
> There are a unumber of contact at each company.  I have created a Windows
> form where I can select a contact, all of the information about the contact
> (tblContact), and the information about the (tblCompany) appears and can be
> edited.
>
> If I try to add a new contact, at a new company; the contact information is
> saved to tblContact, but the company is not saved.  Edit can be made to any
> field for either table, but new records cannot be added to the company table.
>
> The code is:
>
> Private Sub TblContactBindingNavigatorSaveItem_Click(ByVal sender _
>     As System.Object, ByVal e As System.EventArgs) _
>     Handles TblContactsBindingNavigatorSaveItem.Click
>         'save, update records
>         Me.Validate()
>         Me.TblCompanyBindingSource.EndEdit()
>         Me.TblCompanyTableAdapter.Update(Me.DsContactData.tblCoAddress)
>
>         Me.TblContactBindingSource.EndEdit()
>         Me.TblContactTableAdapter.Update(Me.DsContactData.tblContact)
>     End Sub
>
> When I run the program no errors appear, but nothing is saved to the
> tblCompany table. Any help will be appreciated.
>
> --
> Tony
Author
22 Sep 2006 5:15 AM
Cor Ligthert [MVP]
K,

Be aware that in this approach the acceptchanges should be used on the
original table. The getchanges gives a copy. I tell that because it was a
mistake that I made the first time I was using this.

Cor

Show quoteHide quote
"kgerritsen" <ki***@drexel.edu> schreef in bericht
news:1158865429.758803.183500@m7g2000cwm.googlegroups.com...
> Tony,
>
> Two ideas:  First, is there any referential integrity defined in the
> Access database on the foreign key CompNum?  If so, I'd actually expect
> the reverse (no new contact insert until the company was inserted), but
> I have experienced Access get the integrity relationship backwards once
> before.
>
> When using table adapter update, I've been more successful with
> extracting a changed dataset as in the following approach:
>                Dim dschg As DataSet
>                dschg = ds.GetChanges()
>
>                If Not dschg Is Nothing Then
>                    da.Update(dschg, SqlTable)
>                End If
>
> Actually, a third idea: make sure there are no nulls or type-illegal
> data in the tblCompany rows.
>
> Regards,
> Keith
>
> Tony A. wrote:
>> I'm using VB .Net 2005 with Access 2003 for the database.  The database
>> has
>> two tables:  tblContact (ContactNum (k), lastname, firstname, phone,
>> email,
>> compNum) and tblCompany (CompNun (k), CompName, address, city, state,
>> zip,
>> compNum)
>>
>> There are a unumber of contact at each company.  I have created a Windows
>> form where I can select a contact, all of the information about the
>> contact
>> (tblContact), and the information about the (tblCompany) appears and can
>> be
>> edited.
>>
>> If I try to add a new contact, at a new company; the contact information
>> is
>> saved to tblContact, but the company is not saved.  Edit can be made to
>> any
>> field for either table, but new records cannot be added to the company
>> table.
>>
>> The code is:
>>
>> Private Sub TblContactBindingNavigatorSaveItem_Click(ByVal sender _
>>     As System.Object, ByVal e As System.EventArgs) _
>>     Handles TblContactsBindingNavigatorSaveItem.Click
>>         'save, update records
>>         Me.Validate()
>>         Me.TblCompanyBindingSource.EndEdit()
>>         Me.TblCompanyTableAdapter.Update(Me.DsContactData.tblCoAddress)
>>
>>         Me.TblContactBindingSource.EndEdit()
>>         Me.TblContactTableAdapter.Update(Me.DsContactData.tblContact)
>>     End Sub
>>
>> When I run the program no errors appear, but nothing is saved to the
>> tblCompany table. Any help will be appreciated.
>>
>> --
>> Tony
>