|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Problem Adding new record to a databasetwo 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 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 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. -- Show quoteHide quoteTony "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 > > 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 >> >> 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. -- Show quoteHide quoteTony "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 > >> > >> > > > 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 >> >> >> >> >> >> >> 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 Build a release. Run the release executable, make some changes and then exit. Rerun>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. the release executable and see if the changes are shown. Gene 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 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 >
Slow startup of Deployed Application
How to reset Windows Application's default programmatically? What is the Best Icon Maker? Display Crystal Report Passing data from one VB.Net application to another Data Access Tad bit of combo box newbie help, please! Is this the most efficient/fastest code to use? (beginner sql question) how to do this? Issues with scope on a text box after .net conversion from vb6 |
|||||||||||||||||||||||