473,507 Members | 2,374 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Load a Generic class without Loop

8 New Member
ok this is the thing I have right now which is working quite well beside its a bit slow:

Public Function GetList() As List(Of SalesOrder)
Try
Dim list As New List(Of SalesOrder)

Dim ds As DataSet

ds = cls.GetSalesOrderList 'CLS is the data access class


For i = 0 To ds.Tables(0).Rows.Count - 1

Dim row As DataRow = ds.Tables(0).Rows(i)
Dim kk As SalesOrder = New SalesOrder()


kk.ID = Val(row.Item("id") & "")
kk.SalesOrderNo = row.Item("salesorderid") & ""
kk.SalesOrderDate = row.Item("OrderDate") & ""
kk.CustomerId = Val(row.Item("customerid") & "")

list.Add(kk)

Next
Return list

Catch ex As Exception
Throw ex
End Try

End Function

Now once I start retrieving more than 10000 records from the table, the loop takes long time to load values into generic class. Is there any way that I can get rid of loop? Can I do something like the following with the generic class?

txtSearch.AutoCompleteCustomSource.AddRange(Array. ConvertAll(Of DataRow, String)(BusinessLogic.ToDataTable.ConvertTo(WorkOr derList).Select(), Function(row As DataRow) row("TradeContactName")))
Jul 15 '10 #1
2 1360
Aimee Bailey
197 Recognized Expert New Member
I do something similar in work, though i stay away from data adapters as i find them ill efficient. Can i ask why you need to draw so many sales orders from a database? seems a bit unusual.
Jul 24 '10 #2
Joseph Martell
198 Recognized Expert New Member
You can't really get rid of the loop. Even if you use some sort of AddRange variant, there is still an internal loop.

If you are looking to squeeze every ounce of performance from this that you can I would start looking at things like how you are accessing your object and any operations you can eliminate. For example, you are referencing your columns by name when processing your row object. This requires some string matching to occur. You could use a numeric column index instead. Also, from this documentation, use a With block to refer to your kk object (after the new statement) and you may find a very slight performance increase. I'm sure ther are other things you could do.

Finally, the best thing you can do is re-evaluate how you are running your query. It is rarely the required case to return everything from a table in a database. Filtering records out will be far more efficient if the SQL Server handles it instead of doing it locally in VB.

If the entire table must be retrieved, then you may want to consider parrallel processing of some kind. Of course, this has its own pitfalls and difficulties.
Jul 26 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

16
1699
by: Crirus | last post by:
I have a class. I need to write a routine in this class, that loop through it's members (in a instance of the class) and concatenate all members values as string. I need to filter does members...
12
1836
by: Elhanan | last post by:
hi.. i wanted to build a Dictionary Classs that will load my own class called letter, i understood that i implement the IEquatable interface's equles method that then the dictionary would use...
2
1622
by: RFOG | last post by:
Hi all! I need a class that will be capable to enumerate some internal data, then my idea is to implement "for each" loop access. Doc says that I've to inherit form IEnumerable, but then...
2
9854
by: AdawayNoSpam | last post by:
Said that I have the following class Class MyRootClass(Of T) End Class Class MySubClass1(Of T) Inherits MyRootClass(Of T) End Class
4
9156
by: Hyun-jik Bae | last post by:
Is that not allowed to assume generic type numeric type? As far as I've tried, I got an error with the following code: public class AAA<T> { public int Foo(T a) { return a; // error: Cannot...
10
1912
by: Egghead | last post by:
Hi all, Can someone kindly enough point me to some situations that we shall or "must" use Generic Class? I can foresee the Generic Method is powerful, but I can not find a single situation that...
10
2901
by: fig000 | last post by:
HI, I'm new to generics. I've written a simple class to which I'm passing a generic list. I'm able to pass the list and even pass the type of the list so I can use it to traverse it. It's a...
2
2866
by: Andrew Backer | last post by:
I hope someone out there can help me with this, because I am stuck. My problem is that I have an instance of a generic class, but I don't know ahead of time what the type parameter used was. In...
8
3137
by: MMAS | last post by:
Hey everyone -- Curious about some strange behaviour I'm seeing that seems to be related to my lack of understanding on how generics work in C#. Here's some simplified code (sorry for strange...
1
2444
by: raylopez99 | last post by:
Here is an example of a home grown generic class, representing a pair of values. Adapted from Jon Skeet's book "C# In Depth". The generic class is "sealed" for some reason (I think for...
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7485
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.