|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
referential integrityI'm trying to create a form to maintain 2 MS Access RELATED tables
'Parent' and 'Child'. I use 2 datagrids that are binded to 2 datatables. I've created 2 dataadapters and filled the datasets. I try to modify in the datagrid a NON key field of the 'Parent' tale and call the update method. An exception is raised; the message translation is: "Is is not possible to modify or delete the record. 'Child' table contains related records". Why ADO.NET doesn't allow me to modify the record even if this doesn't violate the referential integrity of the database? Thank you in advance... -- Simone Am Tue, 5 Jul 2005 03:26:01 -0700 schrieb simo71:
> I'm trying to create a form to maintain 2 MS Access RELATED tables I have the same problem. It would be nice if someone can give a helping> 'Parent' and 'Child'. I use 2 datagrids that are binded to 2 datatables. > I've created 2 dataadapters and filled the datasets. I try to modify in the > datagrid a NON key field of the 'Parent' tale and call the update method. An > exception is raised; the message translation is: "Is is not possible to > modify or delete the record. 'Child' table contains related records". Why > ADO.NET doesn't allow me to modify the record even if this doesn't violate > the referential integrity of the database? hint. Mfg Frank Loizzi Germany Simone:
I'm not totaly sure of the answer for your issue because I also have hard time getting answers on relational concepts with VB.NET. I've read through two books and never get a difinitive answer there or in the groups. Visual Basic Step by Step by Michael Halvorson and Programming Visual Basic .NET by Francesco Balena Two very good books. Although, one thing I have learned is that if your building a VB.NET application wraped around an MS Access db, you want to remove all your relationships in the DB itself and use the VB GUI to create them. It has the ability to enforce referential integrity and all the other stuff. The relationships inside the DB seem to conflict with relationships in VB. If this is already the case, then I've always had moderate success creating the form using the windows form wizard and then working with that. If I ever figure it out beyond that, I'll certainly fill you in Good Luck Bob Am Wed, 13 Jul 2005 09:57:24 GMT schrieb Bob:
> Although, one thing I have learned is that if your building a VB.NET Bob! You are a hero! :-)> application wraped around an MS Access db, you want to remove all your > relationships in the DB itself and use the VB GUI to create them. It has the > ability to enforce referential integrity and all the other stuff. The > relationships inside the DB seem to conflict with relationships in VB. > > If this is already the case, then I've always had moderate success creating > the form using the windows form wizard and then working with that. > > If I ever figure it out beyond that, I'll certainly fill you in After two weeks of vexation finally I got it. Whith your help... :-) Thats a problem which nowhere is described. No Microsoft article no website. Very frustrating. I deleted only the relations in my database (which is programmatically generated) and the application works like desired. Now I have only relations generated bei ADO.NET. Thanks a million... Mfg Frank Loizzi Germany Bob, Frank,
First of all, thank you for your attention. As Frank says, the problem is not described probably over the whole Internet and Bob gave us a first solution. But... this solution cannot be applied to my problem, because the data in the DB is used by another WEB application, so I cannot delete the relationships from the DB. Consider that I've moved my DB on SQL Server and... the problem disappeared!!! Unfortunately I must use MSAccess, and so I've tried to modify the connection string in different ways (using ODBC, changing the mode etc) without success... Any other idea? thank you again Simone -- Show quoteHide quoteSimone "Bob" wrote: > Simone: > > I'm not totaly sure of the answer for your issue because I also have hard > time getting answers on relational concepts with VB.NET. > > I've read through two books and never get a difinitive answer there or in > the groups. > > Visual Basic Step by Step by Michael Halvorson and > Programming Visual Basic .NET by Francesco Balena > > Two very good books. > > Although, one thing I have learned is that if your building a VB.NET > application wraped around an MS Access db, you want to remove all your > relationships in the DB itself and use the VB GUI to create them. It has the > ability to enforce referential integrity and all the other stuff. The > relationships inside the DB seem to conflict with relationships in VB. > > If this is already the case, then I've always had moderate success creating > the form using the windows form wizard and then working with that. > > If I ever figure it out beyond that, I'll certainly fill you in > > Good Luck > > Bob > > > Simone, and others, I have attempted to simulate
your problem with a two table MS Access DB. One parent and one child. There is a one-to-many relation between the two tables. I have maintined referntial integrity between them. I then load them into a VB app with two data grids. Each DB table has its own command and dataadater. I have filled a single data set with the two tables. I used a command builder (for speed) to create the update, insert and delete commands for me. I altered data in the parent table, performed an update and all worked fine. I even modified the child and then both to make sure there was nothing wierd going on. Maybe I am missing some of your problem but my demo is working fine. Let me know if you are still having problems and I will see if I can help. Regards, Jason. On Fri, 29 Jul 2005 05:07:02 -0700, =?Utf-8?B?c2ltbzcx?= <simo71_nospam@virgilio.it> wrote: Show quoteHide quote >Bob, Frank, >First of all, thank you for your attention. > >As Frank says, the problem is not described probably over the whole Internet >and Bob gave us a first solution. >But... this solution cannot be applied to my problem, because the data in >the DB is used by another WEB application, so I cannot delete the >relationships from the DB. > >Consider that I've moved my DB on SQL Server and... the problem disappeared!!! >Unfortunately I must use MSAccess, and so I've tried to modify the >connection string in different ways (using ODBC, changing the mode etc) >without success... > >Any other idea? > >thank you again >Simone > > >-- >Simone > > >"Bob" wrote: > >> Simone: >> >> I'm not totaly sure of the answer for your issue because I also have hard >> time getting answers on relational concepts with VB.NET. >> >> I've read through two books and never get a difinitive answer there or in >> the groups. >> >> Visual Basic Step by Step by Michael Halvorson and >> Programming Visual Basic .NET by Francesco Balena >> >> Two very good books. >> >> Although, one thing I have learned is that if your building a VB.NET >> application wraped around an MS Access db, you want to remove all your >> relationships in the DB itself and use the VB GUI to create them. It has the >> ability to enforce referential integrity and all the other stuff. The >> relationships inside the DB seem to conflict with relationships in VB. >> >> If this is already the case, then I've always had moderate success creating >> the form using the windows form wizard and then working with that. >> >> If I ever figure it out beyond that, I'll certainly fill you in >> >> Good Luck >> >> Bob >> >> >> Jason:
You probably didn't create relationships in the Schema designer for the dataset within VB. To answer Paul, Yes you can use VB.NET with ADO.NET wrapped around an Access DB. I guess it's assumed that if your using VB.NET to build a front end for an Access DB, then you will use VB.NET features and relational concepts. Not Access. Access will simply hold the tables. Now your clients, or you will not have to license and install multiple copies of MS access to store data in Access tables. On another note, MSDE, MS SQL, MS SQL Express 2005 would be better choices for a backend. It does work even when you create relationships in the DB. They also lets you specify cascade delete which will save you a lot of code if your app is large. You can also generate SQL scripts withing VB's IDE so you can transport your backend SQL Server schema. HTH Bob Bob,
are you talking about typed data sets? If not then why would I need the schema designer. If if load the schema, using fillschema, then everything still works fine! Thanks, Jason. Show quoteHide quote On Tue, 13 Sep 2005 21:36:00 GMT, "Bob" <nojunk@nospammers.com> wrote: >Jason: > >You probably didn't create relationships in the Schema designer for the >dataset within VB. > >To answer Paul, Yes you can use VB.NET with ADO.NET wrapped around an Access >DB. I guess it's assumed that if your using VB.NET to build a front end for >an Access DB, then you will use VB.NET features and relational concepts. Not >Access. Access will simply hold the tables. Now your clients, or you will >not have to license and install multiple copies of MS access to store data >in Access tables. > >On another note, MSDE, MS SQL, MS SQL Express 2005 would be better choices >for a backend. It does work even when you create relationships in the DB. >They also lets you specify cascade delete which will save you a lot of code >if your app is large. You can also generate SQL scripts withing VB's IDE so >you can transport your backend SQL Server schema. > >HTH > >Bob > > Bob,
I recreated by app using a typed dataset and added the relationship in schema designer to cascade updates and deletes, and I can still update the fields in my parent record and write the changes back to the MS Access DB! Thanks, Jason. Show quoteHide quote On Tue, 13 Sep 2005 21:36:00 GMT, "Bob" <nojunk@nospammers.com> wrote: >Jason: > >You probably didn't create relationships in the Schema designer for the >dataset within VB. > >To answer Paul, Yes you can use VB.NET with ADO.NET wrapped around an Access >DB. I guess it's assumed that if your using VB.NET to build a front end for >an Access DB, then you will use VB.NET features and relational concepts. Not >Access. Access will simply hold the tables. Now your clients, or you will >not have to license and install multiple copies of MS access to store data >in Access tables. > >On another note, MSDE, MS SQL, MS SQL Express 2005 would be better choices >for a backend. It does work even when you create relationships in the DB. >They also lets you specify cascade delete which will save you a lot of code >if your app is large. You can also generate SQL scripts withing VB's IDE so >you can transport your backend SQL Server schema. > >HTH > >Bob > > Sorry for the delay in the answer and thank you for the attention.
I can post the source code or if you want, a could place the files in a public ftp server. Here I try to paste the source code. If you modify th field "valore" in table Padre and try to sync the exception arise. Regards. Simone. ********* DB *********** Table Padre (Father) Num; Anno; valore 1;"2005";"35345345" 2;"2005";"dfgdfg" Table provaF (Son) chiaveF;Num; Anno; valore 100;1;"2005";"ggggg" 101;1;"2005";"ghhhfghrthrh" 102;2;"2005";"hhhhh" ********* Form1.vb *********** Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid Friend WithEvents DataGrid2 As System.Windows.Forms.DataGrid Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents Button2 As System.Windows.Forms.Button Friend WithEvents Button3 As System.Windows.Forms.Button Friend WithEvents Button4 As System.Windows.Forms.Button Friend WithEvents OleDbDataAdapterFIGLIO As System.Data.OleDb.OleDbDataAdapter Friend WithEvents OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand Friend WithEvents OleDbInsertCommand1 As System.Data.OleDb.OleDbCommand Friend WithEvents OleDbUpdateCommand1 As System.Data.OleDb.OleDbCommand Friend WithEvents OleDbDeleteCommand1 As System.Data.OleDb.OleDbCommand Friend WithEvents DataSet11 As test.DataSet1 Friend WithEvents OleDbDataAdapterPADRE As System.Data.OleDb.OleDbDataAdapter Friend WithEvents OleDbSelectCommand2 As System.Data.OleDb.OleDbCommand Friend WithEvents OleDbInsertCommand2 As System.Data.OleDb.OleDbCommand Friend WithEvents OleDbUpdateCommand2 As System.Data.OleDb.OleDbCommand Friend WithEvents OleDbDeleteCommand2 As System.Data.OleDb.OleDbCommand Friend WithEvents OleDbConnection1OLD As System.Data.OleDb.OleDbConnection <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.DataGrid1 = New System.Windows.Forms.DataGrid Me.DataSet11 = New test.DataSet1 Me.DataGrid2 = New System.Windows.Forms.DataGrid Me.Button1 = New System.Windows.Forms.Button Me.Button2 = New System.Windows.Forms.Button Me.Button3 = New System.Windows.Forms.Button Me.Button4 = New System.Windows.Forms.Button Me.OleDbDataAdapterFIGLIO = New System.Data.OleDb.OleDbDataAdapter Me.OleDbDeleteCommand1 = New System.Data.OleDb.OleDbCommand Me.OleDbConnection1OLD = New System.Data.OleDb.OleDbConnection Me.OleDbInsertCommand1 = New System.Data.OleDb.OleDbCommand Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand Me.OleDbUpdateCommand1 = New System.Data.OleDb.OleDbCommand Me.OleDbDataAdapterPADRE = New System.Data.OleDb.OleDbDataAdapter Me.OleDbDeleteCommand2 = New System.Data.OleDb.OleDbCommand Me.OleDbInsertCommand2 = New System.Data.OleDb.OleDbCommand Me.OleDbSelectCommand2 = New System.Data.OleDb.OleDbCommand Me.OleDbUpdateCommand2 = New System.Data.OleDb.OleDbCommand CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.DataGrid2, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'DataGrid1 ' Me.DataGrid1.DataMember = "" Me.DataGrid1.DataSource = Me.DataSet11.Padre Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText Me.DataGrid1.Location = New System.Drawing.Point(24, 24) Me.DataGrid1.Name = "DataGrid1" Me.DataGrid1.Size = New System.Drawing.Size(416, 256) Me.DataGrid1.TabIndex = 0 ' 'DataSet11 ' Me.DataSet11.DataSetName = "DataSet1" Me.DataSet11.Locale = New System.Globalization.CultureInfo("it-IT") ' 'DataGrid2 ' Me.DataGrid2.DataMember = "" Me.DataGrid2.DataSource = Me.DataSet11.provaF Me.DataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText Me.DataGrid2.Location = New System.Drawing.Point(472, 24) Me.DataGrid2.Name = "DataGrid2" Me.DataGrid2.Size = New System.Drawing.Size(268, 256) Me.DataGrid2.TabIndex = 1 ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(32, 312) Me.Button1.Name = "Button1" Me.Button1.TabIndex = 2 Me.Button1.Text = "Fill Father" ' 'Button2 ' Me.Button2.Location = New System.Drawing.Point(480, 312) Me.Button2.Name = "Button2" Me.Button2.TabIndex = 3 Me.Button2.Text = "Fill Son" ' 'Button3 ' Me.Button3.Location = New System.Drawing.Point(360, 312) Me.Button3.Name = "Button3" Me.Button3.TabIndex = 4 Me.Button3.Text = "sync Father" ' 'Button4 ' Me.Button4.Location = New System.Drawing.Point(664, 312) Me.Button4.Name = "Button4" Me.Button4.TabIndex = 5 Me.Button4.Text = "sync Son" ' 'OleDbDataAdapterFIGLIO ' Me.OleDbDataAdapterFIGLIO.DeleteCommand = Me.OleDbDeleteCommand1 Me.OleDbDataAdapterFIGLIO.InsertCommand = Me.OleDbInsertCommand1 Me.OleDbDataAdapterFIGLIO.SelectCommand = Me.OleDbSelectCommand1 Me.OleDbDataAdapterFIGLIO.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "provaF", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("Anno", "Anno"), New System.Data.Common.DataColumnMapping("chiaveF", "chiaveF"), New System.Data.Common.DataColumnMapping("Num", "Num"), New System.Data.Common.DataColumnMapping("valore", "valore")})}) Me.OleDbDataAdapterFIGLIO.UpdateCommand = Me.OleDbUpdateCommand1 ' 'OleDbDeleteCommand1 ' Me.OleDbDeleteCommand1.CommandText = "DELETE FROM provaF WHERE (chiaveF = ?) AND (Anno = ? OR ? IS NULL AND Anno IS NUL" & _ "L) AND (Num = ? OR ? IS NULL AND Num IS NULL) AND (valore = ? OR ? IS NULL AND v" & _ "alore IS NULL)" Me.OleDbDeleteCommand1.Connection = Me.OleDbConnection1OLD Me.OleDbDeleteCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_chiaveF", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "chiaveF", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbDeleteCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Anno", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Anno", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbDeleteCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Anno1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Anno", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbDeleteCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Num", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Num", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbDeleteCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Num1", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Num", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbDeleteCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_valore", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "valore", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbDeleteCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_valore1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "valore", System.Data.DataRowVersion.Original, Nothing)) ' 'OleDbConnection1OLD ' Me.OleDbConnection1OLD.ConnectionString = "Mode=Share Exclusive;Data Source=""C:\1locale\test su access\test.mdb"";Provider=""M" & _ "icrosoft.Jet.OLEDB.4.0"";User ID=Admin;" ' 'OleDbInsertCommand1 ' Me.OleDbInsertCommand1.CommandText = "INSERT INTO provaF(Anno, chiaveF, Num, valore) VALUES (?, ?, ?, ?)" Me.OleDbInsertCommand1.Connection = Me.OleDbConnection1OLD Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Anno", System.Data.OleDb.OleDbType.VarWChar, 50, "Anno")) Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("chiaveF", System.Data.OleDb.OleDbType.Integer, 0, "chiaveF")) Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Num", System.Data.OleDb.OleDbType.Integer, 0, "Num")) Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("valore", System.Data.OleDb.OleDbType.VarWChar, 50, "valore")) ' 'OleDbSelectCommand1 ' Me.OleDbSelectCommand1.CommandText = "SELECT Anno, chiaveF, Num, valore FROM provaF" Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1OLD ' 'OleDbUpdateCommand1 ' Me.OleDbUpdateCommand1.CommandText = "UPDATE provaF SET Anno = ?, chiaveF = ?, Num = ?, valore = ? WHERE (chiaveF = ?) " & _ "AND (Anno = ? OR ? IS NULL AND Anno IS NULL) AND (Num = ? OR ? IS NULL AND Num I" & _ "S NULL) AND (valore = ? OR ? IS NULL AND valore IS NULL)" Me.OleDbUpdateCommand1.Connection = Me.OleDbConnection1OLD Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Anno", System.Data.OleDb.OleDbType.VarWChar, 50, "Anno")) Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("chiaveF", System.Data.OleDb.OleDbType.Integer, 0, "chiaveF")) Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Num", System.Data.OleDb.OleDbType.Integer, 0, "Num")) Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("valore", System.Data.OleDb.OleDbType.VarWChar, 50, "valore")) Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_chiaveF", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "chiaveF", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Anno", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Anno", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Anno1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Anno", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Num", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Num", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Num1", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Num", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_valore", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "valore", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_valore1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "valore", System.Data.DataRowVersion.Original, Nothing)) ' 'OleDbDataAdapterPADRE ' Me.OleDbDataAdapterPADRE.DeleteCommand = Me.OleDbDeleteCommand2 Me.OleDbDataAdapterPADRE.InsertCommand = Me.OleDbInsertCommand2 Me.OleDbDataAdapterPADRE.SelectCommand = Me.OleDbSelectCommand2 Me.OleDbDataAdapterPADRE.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Padre", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("Anno", "Anno"), New System.Data.Common.DataColumnMapping("Num", "Num"), New System.Data.Common.DataColumnMapping("valore", "valore")})}) Me.OleDbDataAdapterPADRE.UpdateCommand = Me.OleDbUpdateCommand2 ' 'OleDbDeleteCommand2 ' Me.OleDbDeleteCommand2.CommandText = "DELETE FROM Padre WHERE (Anno = ?) AND (Num = ?) AND (valore = ? OR ? IS NULL AND" & _ " valore IS NULL)" Me.OleDbDeleteCommand2.Connection = Me.OleDbConnection1OLD Me.OleDbDeleteCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Anno", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Anno", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbDeleteCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Num", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Num", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbDeleteCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_valore", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "valore", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbDeleteCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_valore1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "valore", System.Data.DataRowVersion.Original, Nothing)) ' 'OleDbInsertCommand2 ' Me.OleDbInsertCommand2.CommandText = "INSERT INTO Padre(Anno, Num, valore) VALUES (?, ?, ?)" Me.OleDbInsertCommand2.Connection = Me.OleDbConnection1OLD Me.OleDbInsertCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Anno", System.Data.OleDb.OleDbType.VarWChar, 50, "Anno")) Me.OleDbInsertCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Num", System.Data.OleDb.OleDbType.Integer, 0, "Num")) Me.OleDbInsertCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("valore", System.Data.OleDb.OleDbType.VarWChar, 50, "valore")) ' 'OleDbSelectCommand2 ' Me.OleDbSelectCommand2.CommandText = "SELECT Anno, Num, valore FROM Padre" Me.OleDbSelectCommand2.Connection = Me.OleDbConnection1OLD ' 'OleDbUpdateCommand2 ' Me.OleDbUpdateCommand2.CommandText = "UPDATE Padre SET Anno = ?, Num = ?, valore = ? WHERE (Anno = ?) AND (Num = ?) AND" & _ " (valore = ? OR ? IS NULL AND valore IS NULL)" Me.OleDbUpdateCommand2.Connection = Me.OleDbConnection1OLD Me.OleDbUpdateCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Anno", System.Data.OleDb.OleDbType.VarWChar, 50, "Anno")) Me.OleDbUpdateCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Num", System.Data.OleDb.OleDbType.Integer, 0, "Num")) Me.OleDbUpdateCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("valore", System.Data.OleDb.OleDbType.VarWChar, 50, "valore")) Me.OleDbUpdateCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Anno", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Anno", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbUpdateCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Num", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Num", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbUpdateCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_valore", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "valore", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbUpdateCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_valore1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "valore", System.Data.DataRowVersion.Original, Nothing)) ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(792, 414) Me.Controls.Add(Me.Button4) Me.Controls.Add(Me.Button3) Me.Controls.Add(Me.Button2) Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.DataGrid2) Me.Controls.Add(Me.DataGrid1) Me.Name = "Form1" Me.Text = "Form1" CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.DataGrid2, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try OleDbDataAdapterPADRE.Fill(DataSet11.Padre) MsgBox("filled Father") Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Try OleDbDataAdapterPADRE.Update(DataSet11.Padre) MsgBox("sync Father") Catch ex As Exception MsgBox(ex.Message & " source=" & ex.Source & " StackTrace=" & ex.StackTrace) End Try End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try OleDbDataAdapterFIGLIO.Fill(DataSet11.provaF) MsgBox("filled Son") Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Try OleDbDataAdapterFIGLIO.Update(DataSet11.provaF) MsgBox("sync Son") Catch ex As Exception MsgBox(ex.Message) End Try End Sub End Class Hi there!
I am glad I found this thread because I came to the same conclusion but did not want to accept it, especially since I spent so much time setting the relationships up in the first place (in the Db)! It does not make sense that VB.NET through ADO.NET can't simply be the front end to the Access DB in the back. I now use a datagrid to show one of my child tables, but one column contains data from another (parent) which I want the user to select when adding a new child record, just as he would when having the table open in Access (a dropdown list would appear when selecting the field). How do I get this 'parent' column to display the same dropdown list in the datagrid as in Access itself? In my datagrid, the new record does not show the valid options in this field, thus the user is forced to type it in and make sure his entry is correctly spelled(!). Hope you have the answer. Regards Paul Show quoteHide quote "Bob" wrote: > Simone: > > I'm not totaly sure of the answer for your issue because I also have hard > time getting answers on relational concepts with VB.NET. > > I've read through two books and never get a difinitive answer there or in > the groups. > > Visual Basic Step by Step by Michael Halvorson and > Programming Visual Basic .NET by Francesco Balena > > Two very good books. > > Although, one thing I have learned is that if your building a VB.NET > application wraped around an MS Access db, you want to remove all your > relationships in the DB itself and use the VB GUI to create them. It has the > ability to enforce referential integrity and all the other stuff. The > relationships inside the DB seem to conflict with relationships in VB. > > If this is already the case, then I've always had moderate success creating > the form using the windows form wizard and then working with that. > > If I ever figure it out beyond that, I'll certainly fill you in > > Good Luck > > Bob > > >
Other interesting topics
sqlDataAdapters/
Cast from string to type integer newbie questions Emergency: Unicode Characters in a Dataset. The best online ADO resource sql query against an in memory dataset with VFP COM components How Can I retreive all the SQL server on my LAN ? DataReader,ArrayList, ListBox How to filter a Dataset and save it into Xml ? Need OLEDB Connect String Example for Sybase |
|||||||||||||||||||||||