index > .NET Framework Data Access and Storage > Master Detail Records

Master Detail Records

Hi!

I am learning VB.Net programming and having some problem with master detail records. It works fine when I follow all the norms of master detail data entry i.e. when I insert a record in master table and save that record and then add the records in child table using grid then everything works fine and even the grid automatically displays the value of the field which is common in both the tables.

But the problem is that I've a situation in which I've to enter the master and details record at the same time. Actually I am creating a loan registration form, in which along with all other details of the loan, I have to enter the details of the guarantors, the number of guarantors depends on the amount of the loan taken. So whenever I will register a new loan I'll have to enter the guarantors detail at the same time in a datagridview control.

At the moment I am filling all the master table fields in the form, leaving details grid blank and then save that record, then I reopen that record in edit mode and then enter the child(Guarantor) records. But as it seems it is not a practical solution.

So please help me in this regard. I will be very very thankful to you.

Regards,

SHISHIR WAHI

Hi,

Actually this is just fine. All you have to do is to insert your master record first and then your child records after. But you must do this at the same time in your Save button. I think you are being confused here since your form would contain all of your inputs.

Or you can just have a temporary storage for your child records first. Then add it to your datatable after youve already added your master record.

BTW, are you using plain DataTables and DataSets? Or are you using Typed Datasets and binding your controls into it?

cheers,

Paul June A. Domag




Visit my Online Blog - http://webmag.mvps.org
Paul Domag

Hi.

Thanks for the reply. But I am still confused coz it should happen in the same way as you told, i.e master record should be entered first then all the child records should be entered and then when I press the SAVE button then master records should be saved first and then the child table should be updated, but its not happening, as soon as I enter the master record and then the first child record in the grid and move to next row it gives the error that the ForeignKeyConstraint FK_LoanReg_LReg requires the child key values to exist in the parent table, and all the fields in the grid are reset.

BTW I am using SQLDataAdapters and Datasets. The code I am using to update records are as follows:-

Public Sub UpdateDataSet()

Dim objDataSetChanges As Cooperative.dsGLoan = New Cooperative.dsGLoan()

Me.BindingContext(DsGLoan1, "LoanReg").EndCurrentEdit()

objDataSetChanges = CType(DsGLoan1.GetChanges, Cooperative.dsGLoan)

If (Not (objDataSetChanges) Is Nothing) Then

Try

Me.UpdateDataSource(objDataSetChanges)

DsGLoan1.AcceptChanges()

Catch eUpdate As System.Exception

Throw eUpdate

End Try

End If

End Sub

Public Sub UpdateDataSource(ByVal ChangedRows As Cooperative.dsGLoan)

Try

If (Not (ChangedRows) Is Nothing) Then

If Me.SqlConnection1.State = ConnectionState.Closed Then

SqlConnection1.Open()

End If

SqlDataAdapter1.Update(ChangedRows)

SqlDataAdapter2.Update(ChangedRows)

SqlDataAdapter4.Update(ChangedRows)

End If

Catch UpdateException As System.Exception

Throw UpdateException

Finally

Me.SqlConnection1.Close()

End Try

End Sub




Shishir
SHISHIR WAHI
reply 3

You can use google to search for other answers

 

More Articles

• Trusted_Connection Problem with VS2005
• insert row into table with autoincrement primary key
• how to show rows in dataset when filling it? as wizzard do.
• SQLDataSource
• Desiging Data Access
• DataView RowFilter not filtering on percent sign
• add parameters to oledb
• OleDbDataAdapter, Fill, Update, CommandBuilder and PrimaryKeys
• OleDbCommandBuilder doesn't generate anything...
• subquery doesn't work (using VC#, *.csv, ADO.NET , OLEDB)
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Urgent! Pls answer me. Database.
• Using diffgram to update database
• Failed to convert parameter value from a
• Expression Building - Access 2003
• Error generating a DataSet from an Oracl
• SQLCommand insert not working for datase
• Retrieve output inserted multiple columns
• return output Inserted.ColName value int
• System.Transactions issue
• Rollback during Thread.Abort exception o
• GridView in Web Application Not Deleting
• Deny access to all my .mdb in a directory
• DateTime interpretation between ADO.Net
• Read data from an Opened excel file with
• Reading an OLE Object field in a MS Acce

Hot Articles

• DataSet Vs DataReader????
• How to Manage Transactions
• Load image column from database into ima
• DataSet Size
• SQLBulkCopy and text files.
• data objects and their limitations
• Dinamically adding columns
• Visual Studio 2003 with SQL Server 2005
• Problem using SqlDataAdapter/Query builder
• Advice needed - persist data during a se
• What is the maximum number of tables in
• Query about DataSet
• QUERY written in MS Access does not work
• DataSet, SqlCommand...
• Trusted_Connection Problem with VS2005

Recommend Articles

• Returning controlled SQL data
• insert row into table with autoincrement
• no option to connect system.data.oledb
• unable to upload image to one of two ima
• Time Zone Problem in Web Service
• Automatic Designer Replacement of 'local
• Urgent! Pls answer me. Database.
• Build connection string like COM?
• DB_E_BADROWHANDLE(0x80040E04)]??when usi
• Please Help ME!!! Web Service about Clie
• QUERY written in MS Access does not work
• Exception: DataTable internal index is c
• c#.net: Unable to update records with sq
• Using A Variable In An Excel Query For V
• Client Server Application question, Plea