Jump to content

How to Convert Collection to DataTable

7 replies to this topic

#1 Guest_kittisoongswang_*

  • Guests

Posted 12 October 2005 - 07:37 AM

Can you give me and example of how to convert Collection to Datatable. I saw the following sample code from generated project.

Dim arrayReCustomerOrders As ArrayList = New ArrayList
arrayReCustomerOrders = objInfo.ReCustomerOrders.Items

So I try to convert it to DataTable but did not work.

Please help.

#2 Guest_Paul_*

  • Guests

Posted 12 October 2005 - 01:46 PM

I think you need to add DataSet support in your TierDeveloper project so that you can get dataset object from the query methods. When you enable DataSet Support, TierDeveloper generate dataset interfaces for query methods. For a GetAll query you will be able to call in the following way to get dataset.

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.

#3 Guest_kittisoongswang_*

  • Guests

Posted 12 October 2005 - 06:11 PM

Thank you for information.

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.

#4 Guest_Paul_*

  • Guests

Posted 13 October 2005 - 11:33 AM

Well, the way you are handling this situation looks good and I think you should use SAVE method instead of making separate calls to update, delete and insert. Factory's SAVE method is intended to perform all the standard operations in bulk and within a single transaction.

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.


objFactory.Save(objInfo, 1)

// This will insert a new order into the database

I hope it helps.

#5 Guest_kittisoongswang_*

  • Guests

Posted 13 October 2005 - 06:12 PM

Thank you for suggestion. I will change to use save method.

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.

Kitti S.


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.

Thank anyway.

#6 Guest_Paul_*

  • Guests

Posted 14 October 2005 - 12:03 PM

Yes, you are correct that in order to fully utilize .NET binding capabilities the object collection should implement IBindingList and I think IEditableObject as well (but i'm not sure).

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.


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.

#7 Guest_kittisoongswang_*

  • Guests

Posted 14 October 2005 - 05:41 PM

Since I not very good with OOP and still new with .NET. I will wait for the next release.

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.

Thank you

#8 Guest_Paul_*

  • Guests

Posted 17 October 2005 - 12:45 PM

We are not providing updatable DataSet support in TierDeveloper 5.0 but we will support it in our upcoming release. And, the example that I mentioned in my last thread was just to give you an idea that how you will be able to update a DataSet with single update method (in the next version).

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