1 Replies - 1056 Views - Last Post: 22 July 2012 - 05:47 PM Rate Topic: -----

#1 skylancer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-May 10

N-Tier Typed DataSet

Posted 22 July 2012 - 08:51 AM

I'm in the middle of creating final project "Restaurant Information System" using C# Windows Application. I've a problem when I would like to save order transaction to database using Typed DataSet

There are 2 datagridview, left one to display all menu and right one to store the order details. I've displayed all menu in the left one and when I try to add menu to right one, it's failed. It is failed because I try to add menu to order detail but the order id not set.

The Database structure:

Table Menu : ID (PK), Code, Name, Price
Table Order : ID (PK), Date, Total
Table Order_Detail : ID (PK), Order(FK), Menu(FK), Quantity, Price

and the Typed DataSet has same structure.

I create the project in 3 Tier Architecture using this Walkthrough: Creating N-Tier Data Application (http://msdn.microsoft.com/en-us/library/bb384570.aspx)

updated: I have succeed to add order detail(menu) to right one, but with a little tricky, I create the OrderRow, set its attribute manually, and add to OrderDataTable I create the OrderDetailRow, and set the OrderDetailRow.Order = OrderRow and rest manually but, menu code and menu name do not show in OrderDetail DataGridView

The code:

RestaurantDataSet.OrderRow orderRow = restaurantDataSet.Order.NewOrderRow();
RestaurantDataSet.OrderDetailRow newOrderDetail = restaurantDataSet.OrderDetail.NewOrderDetailRow();

DataRowView dataRowView = (DataRowView)menuBindingSource.Current;
RestaurantDataSet.MenuRow menuRow = (RestaurantDataSet.MenuRow)dataRowView.Row;            

newOrderDetail.OrderRow = orderRow;
newOrderDetail.Order = orderRow.ID;
newOrderDetail.Menu = menuRow.ID;                
newOrderDetail.Price = menuRow.Price;
newOrderDetail.Quantity = (int)nudQuantity.Value;

orderRow.Total = newOrderDetail.Quantity * newOrderDetail.Price; 

restaurantDataSet.OrderDetail.Rows.Add(newOrderDetail);


Furthermore, I try to save the transaction based on article Walkthrough: Saving Data from Related Data Tables (Hierarchical Update) (http://msdn.microsoft.com/en-us/library/bb384432) and Walkthrough: Saving Data to a Database (Multiple Tables) (http://msdn.microsoft.com/en-us/library/4esb49b4) but still failed, I've got error "The INSERT Statement conflicted with the FOREIGN KEY constraint "FK_OrderDetail_Order". The conflict occurred in database "RestaurantDB", table "dbo.Order", column 'ID'. The statement has been terminated."

The code:

RestaurantDataSet.OrderDetailDataTable newOrderDetails = (RestaurantDataSet.OrderDetailDataTable)
                     restaurantDataSet.OrderDetail.GetChanges(DataRowState.Added);

try
{
   // Update the Order table.
   OrderTableAdapter orderAdapter = new OrderTableAdapter();
   orderAdapter.Update(restaurantDataSet.Order);

   if (newOrderDetails != null)
   {
       OrderDetailTableAdapter orderDetailAdapter = new OrderDetailTableAdapter();
       orderDetailAdapter.Update(newOrderDetails);
   }

   restaurantDataSet.AcceptChanges();
}
catch (System.Exception ex)
{
   throw ex;
}


If you have any sample or tutorial, please let me know.

Please don't down vote my question, I really need help. I've googling many times, and not found many tutorial explain N-Tier with Typed Dataset.

Thanks,

Willy

Is This A Good Question/Topic? 0
  • +

Replies To: N-Tier Typed DataSet

#2 immeraufdemhund  Icon User is offline

  • D.I.C Regular

Reputation: 79
  • View blog
  • Posts: 495
  • Joined: 29-March 10

Re: N-Tier Typed DataSet

Posted 22 July 2012 - 05:47 PM

i know you've invested a lot of time using your database and all, but when did you decide that was going to be your method to save all this information? I've been reading a bit on this very subject and although a rational db is sometimes the right solution, sometimes it isn't. If you do want this work I believe the database has a save to XML feature. You could tell each of your databases to "save" then when you start your program to just load said database. That is how I did it on one of my programs and it loads a medium sized 4 table database in about 3 seconds. Plus it is easy enough to edit your data if need be. (though no recommended). Another solution is to make a compact database and just use SQL statements to update/delete to it. All of these solutions to basically do the same thing is what the book was talking about. You have many many many options available to you, and because of that you need to do a little bit of research into which solution will be best. If this is just for a demonstration purpose you might be better to just use hash tables and use a binary writer to save them. So maybe instead of trying to force one solution to work why don't you post up here a little bit more details about system requirements, constraints from your project, or any other details that might shed some light as to which solution will work best for you since you have so many options.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1