473,748 Members | 3,585 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataTable.AddRa nge Slow

I'm finding that the AddRange call in the following code takes several
seconds to execute (approx. 4 seconds).

DataColumn[] adcCols = new DataColumn[3000];
for (int i=0; i<adcCols.Lengt h; i++)
{
adcCols[i] = new DataColumn();
}
myDataTable.Col umns.AddRange(a dcCols);

Is there some way for me to speed this up? I tried using
myDataTable.Beg inLoadData and EndLoadData but it didn't help any. The
end goal is adding 3000 columns to an existing datatable, so if there is
some other way to do that, please let me know.

thanks!

Nov 15 '05 #1
1 12718
Hi Matthew,

Thank you for posting in the community!

I will help you on this issue again:-)

I have tested your code, on my machine, it costs over 30 seconds :-(

Actually, I still did not find a good way to greatly improve the
performance of your issue. The only workaround I can think of is first
generate the schema and write it to the disk. Then, when you want to use it
at runtime, just load the schema dynamicly. Like this:

private void button1_Click(o bject sender, System.EventArg s e)
{
DataTable myDataTable=new DataTable();
DataColumn[] adcCols = new DataColumn[3000];
for (int i=0; i<adcCols.Lengt h; i++)
{
adcCols[i] = new DataColumn();
}
myDataTable.Col umns.AddRange(a dcCols);

DataSet ds=new DataSet();
ds.Tables.Add(m yDataTable);
ds.WriteXmlSche ma(@"C:\test.xm l");
MessageBox.Show ("succeed");
}

private void button2_Click(o bject sender, System.EventArg s e)
{
DateTime dt=DateTime.Now ;
DataSet ds=new DataSet();
ds.ReadXmlSchem a(@"C:\test.xml ");
TimeSpan ts=DateTime.Now- dt;
Console.WriteLi ne(ts.Seconds.T oString());
}

This workaround can improve a little performance on your issue.

Actually I think your design of adding so many columns to a datatable is
not a good one. Can you show the community why you want to add so many
columns to a datatable?

=============== =============== ===
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #2

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

Similar topics

0
3132
by: Dave Elliott | last post by:
After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is after the newly added row without getting bizarre results. I have added the full code for the test below. Create a project drop in the code and run. Any help would be appreciated. Cheers,
2
12129
by: Chris | last post by:
I'm using a DataTable in my application. I am able to load rows into the DataTable quickly. What's puzzling me, however, is that when I update a set of cells in the DataTable, the update is really slow my update code amounts to dataTable.BeginLoadData() dataSet.EnforceConstraints = false tr for(iRowHandle = 0; iRowHandle < iLimit; iRowHandle++
2
8481
by: Ricardo Luceac | last post by:
HI all.. I have a huge table that I want to display in a datagrid, the problem is that if I make a dataset, the entire table must go to the dataset to the data begin to display, and it takes much time... I need to start show data after a row pushed to the dataset, so I think of using the datareader to populate a datatable and bind the datatable to the datagrid.
0
3157
by: Chris Ericoli | last post by:
Hi, I am working with an 'in session' ado dataset with an asp.net application. My dataset is comprised of two tables, one of which maintains a few calculated datacolumns. For some reason these datacolumns do not trigger their expression when other columns from which the expressions are derived are updated. Below is a basic example of what I am doing. User enters values into an asp.net form and clicks a button. Retrieve dataset from...
11
1796
by: Geoff | last post by:
Hi I have a DataTable with thousands of rows. I want a quick way to insert the rows into a table in an Access database with the same structure. I have been using an update command but found it to be very slow i.e. there are about 100,000 rows of data. Can anybody suggest a quick way to do it? Geoff
0
4851
by: Flack | last post by:
I have pasted at the end of this message a small sample program I whipped up to do some testing. It's a form with a datagrid and two buttons. Each button clears the dataTable that is the source of the dataGrid, and then adds five rows. Button2 is the same as button1 just that it does this in a different thread (I was testing if I was having some threading issues). Anyway, it seems that the location of the call to dt.Rows.Clear()...
4
7696
by: Brett Romero | last post by:
I fill a DataTable with search results, which take a very long time if I first clear it. The values come from an object and I map them into the corresponding table columns. I may have 65000 results. I iterate through them, create a new row, fill it, and add it to the DataTable for each interation. This works fine on the first search. Before each search, I call DataTable.Clear() and do the above process. Every search after the first...
4
4743
by: oopman2002 | last post by:
I have created a DataSet DataTable which is comprised of data from a number of sources. The resultant datatable is about 500,000 records and writing them out one at a time takes forever. Does anyone have some example code or tell me how to dump a datatable to Access. One problem is that the datatable structure changes and I would like to create a generic method, which scans the datatable column types and builds the Access table on the...
11
35427
by: inpuarg | last post by:
I have 2 datatables. They are identical. I want to compare them by cell's content. They are all same. But dt1 == dt2 or dt1.GetHashCode() == dt2.GetHashCode() doesn 't work. There are big amount of rows in theese datatables . So i don 't want to enumerate each rows. This is not efficient and unacceptable for my current application.
0
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9312
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4593
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
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 we have to send another system
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.