How to Convert Collection to DataTable
Posted 12 October 2005 - 07:37 AM
Dim arrayReCustomerOrders As ArrayList = New ArrayList
arrayReCustomerOrders = objInfo.ReCustomerOrders.Items
So I try to convert it to DataTable but did not work.
Posted 12 October 2005 - 01:46 PM
CustomerFactory cf = new CustomerFactory();
DataSet ds = cf.GetAllDS();
Now, from this ds object you can get the DataTable object. You can enable DataSet support from Project -> Settings, under "Object Setting" Tab.
Posted 12 October 2005 - 06:11 PM
Actually I try to do master/detail that have edit capability like this. (Use northwind as example)
1. I load customer object with related orders collection.
2. After I load it, I display customer information in master portion and related orders collection in ultragrid from infragistics like this code.
UltraGrid1.DataSource = objInfo.ReCustomerOrders.Items
3. I can manage to write code to delele (I write custom code to use MarkedDeletedItems) and update (grid detect Dirty) data in grid. After that I can update back to data source with code like this.
objFactory.Update(objInfotest, 1) 'objInfotest as global refer to same cust object.
4. Update and Delete code work ok but since objInfo.ReCustomerOrders.Items do not support Add record.
5. Do you have any suggestion for me to make objInfo.ReCustomerOrders.Items have Add capability.
6. I tried to convert it to datatable directly but I can not.
7. I like to have this capability since it will help to write code more easily by using the same update code to make it have insert capability. I think this might work because the IsNew properties of order object in the collection.
8. I also saw IsNew Properties in Save Method but like to have it work with DataGrid. For Dirty properties and MarkedDeletedItems, I can find the way to use it already.
Please give suggestion.
Posted 13 October 2005 - 11:33 AM
If you look at the SAVE method implementation in any factory class you will see that it loops through the collection and based on the flags it determines wheter to update or delete or insert a record in the database.
Here is how you can add a new order to an existing customer.
OrdersFactory objFactory = new OrdersFactory (); Orders objOrder = new Orders(); // Add a new order objOrder.OrderDate = new Date(); ......... .......... // Add the new order to customer's order list. objInfo.ReCustomerOrders.Add(objOrder) objFactory.Save(objInfo, 1) // This will insert a new order into the database
I hope it helps.
Posted 13 October 2005 - 06:12 PM
I still need suggestion about collection that can have insert capability so I can use it as databinding with Grid control.
I tried to find information on this. I found that there is IBindingList interface that can help.
I found one example but I have no idea how to use it with class library that TierDev generate.
If you can help, please take a look at the code at http://www.ntsoft.co...bindinglist.zip. This example is WinForm show IBindingList that can bind to Grid and Add, Edit, Delete capability.
I think if Tiers can produce collection that have capability like this. It will help Tiers users in using Tiers with Grid.
Thank you very much.
I just read this post http://www.alachisof...hl=ibindinglist and found that Alachisoft working on it. So if it not ready now, it ok. I can understand.
Also I could use work around by convert arraylist to datatable directy and bound it to grid. I can use this method for the time being.
Posted 14 October 2005 - 12:03 PM
We are going to add updatable dataset support in the upcoming release and hopefuly they will implement binding interfaces as well. DataSet gives you many features and is quite flexible in use that's why people tend to use DataSet for binding instead of implementing their own binding capabilities in their domain objects.
Here is how you will be able to use dataset (its just to give you an idea the implementation might be different)
DataSet ds = EmployeesFactory.GetAllEmployeesDS(); //Bind the DataSet and make changes in it . //Now pass the modified dataset for persistance. EmplpyeesFactory.UpdateGetAllEmployeesDS(ds);
I've also gone through the sample you told and it seems that you can implement this by customizing the template. However, instead of making changes to these scripts by-hand, you should use the Template IDE that is provided with TierDeveloper.
Posted 14 October 2005 - 05:41 PM
By the way, from your suggestion. I checked with my generated code that also generated dataset. It do not have update via dataset method. It have only get
Is this missing from VB.NET generated code or I need to code it myself.?
If it can generate, please help me by give me information how to generated. If it need to customize template, please help me too.
I still do not have time to learn customize template.
Posted 17 October 2005 - 12:45 PM
Currently, one easy way to process DataSet is by acquiring the modified rows from the DataSet and populate a collection object from that data. You can call factory save method to persist the entire collection with a single call.
Reply to this topic
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users