473,383 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Master Detail

DC
The help article "Walkthrough: Saving Data to a Database (Multiple
Tables)"
in VB 2005 Express does not seem to work. If I add a new Master record
and a
new Detail record at the same time, the Detail record does not contain
the
new Master record id value. I have went through this article a couple
of
times but I can't get it to work. Anyone know how to do this?

Jan 9 '07 #1
2 1039
DC,

If we know how we have to do something, we are not reading again the
walkthrough, you have the change to get an answer from another newbie (which
can be very correct).

Otherwise just show the code from the updating part that you have made.

Cor
Jan 10 '07 #2
DC


Sorry about that Cor, here is the code straight from the help article.

Me.Validate()
Me.OrdersBindingSource.EndEdit()
Me.CustomersBindingSource.EndEdit()

Dim deletedOrders As NorthwindDataSet.OrdersDataTable = CType( _
NorthwindDataSet.Orders.GetChanges(Data.DataRowSta te.Deleted),
NorthwindDataSet.OrdersDataTable)

Dim newOrders As NorthwindDataSet.OrdersDataTable = CType( _
NorthwindDataSet.Orders.GetChanges(Data.DataRowSta te.Added),
NorthwindDataSet.OrdersDataTable)

Dim modifiedOrders As NorthwindDataSet.OrdersDataTable = CType( _
NorthwindDataSet.Orders.GetChanges(Data.DataRowSta te.Modified),
NorthwindDataSet.OrdersDataTable)
Try
' Remove all deleted orders from the Orders table.
If Not deletedOrders Is Nothing Then
OrdersTableAdapter.Update(deletedOrders)
End If

' Update the Customers table.
CustomersTableAdapter.Update(NorthwindDataSet.Cust omers)

' Add new orders to the Orders table.
If Not newOrders Is Nothing Then
OrdersTableAdapter.Update(newOrders)
End If

' Update all modified Orders.
If Not modifiedOrders Is Nothing Then
OrdersTableAdapter.Update(modifiedOrders)
End If

NorthwindDataSet.AcceptChanges()

Catch ex As Exception
MsgBox("Update failed")

Finally
If Not deletedOrders Is Nothing Then
deletedOrders.Dispose()
End If

If Not newOrders Is Nothing Then
newOrders.Dispose()
End If

If Not modifiedOrders Is Nothing Then
modifiedOrders.Dispose()
End If
End Try

The new Orders are added to the database, but not with the new Customer
record. They are added with a blank Customer record Id. If I add new
Orders to an existing Customer then the new Orders contain the correct
Customer Id.
I tried to fix it by adding two sections of code. I entered the
following code before the Try statement.

CurCus = NORTHWNDDataSet.Customers(CustomersBindingSource.P osition) _
("CustomerId", DataRowVersion.Current).ToString

And then the following code after the CustomersTableAdapter.Update
statement.

'update new orders with the new customerid
For x = 0 To newOrders.Count - 1
newOrders.Rows(x)("customerid") = CurCus
Next

But the new Orders were still not saved correctly.

Jan 10 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Marcel | last post by:
Hi, I'm new to VS and ASP.NET and have a question about master/detail datagrids. I have a master datagrid filled with data via a component that contains a SQL adapter. Now I would like to fill...
2
by: ruca | last post by:
Hi, I have a master and a detail datagrid. I put detail grid showing insise of a column of master grid. The problem is that it's not what I really want. What I really want would be that the...
2
by: Ken C | last post by:
I've setup a Master detail table from a typed dataset on 2 different data grid The first one I bind it with the Master data table name The second data set I bind it with the MasterDetail...
2
by: Coen | last post by:
Hello, I have a strange performance delay of about 2 sec's in moving to the next row. I use multiple forms with each master-detail table relations. The master-table displays it's table rows in...
1
by: Sam | last post by:
Attached I am sending 2 URL's from MSFT ASP.net Quick Start Tutorial Web Site. 1) Run it URL: http://www.asp.net/QuickStart/aspnet/samples/data/GridViewMasterDetai... 2) View Source URL:...
0
by: Sam | last post by:
Sorry to post the same post multiple times but the URL Addresses were not Correct in Earlier Posts. Here are the correct URL's: 1) Run It URL is here: ...
1
by: Gary200 | last post by:
Hello All, I bind two datagrids in a master-detail relationship successfully. What I want is to set allowNew and allowDelete disabled in both datagrid using dataview. The code like this: ...
7
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent...
0
by: Mike Wilson | last post by:
Dear group, I have an invoice entry form, which is a simple Master fields / Detail grid. The main summary information of the invoice are stored in one table in a dataset, which is bound using a...
2
by: John | last post by:
Hi I am trying to create a master/detail form. I have my master and details tables dragged onto the dataset. I have also dragged the fields from master table on the form which has created the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.