Hans Rudel
Hans Rudel

Reputation: 3611

DataTable row limit

Morning,

Regarding the following quote, is this limit independent of how many columns there are? (Im assuming not but its not specifically stated anywhere.) If it is linked to the number of columns, how do you calculate that your not over this limit?

To add rows to a DataTable, you must first use the NewRow method to return a new DataRow object. The NewRow method returns a row with the schema of the DataTable, as it is defined by the table's DataColumnCollection. The maximum number of rows that a DataTable can store is 16,777,216. For more information, see Adding Data to a DataTable.

"Link to where quote was taken from."

Thanks for your help.

Upvotes: 1

Views: 7928

Answers (3)

Vijay EK
Vijay EK

Reputation: 184

You can use the DataTable.Rows.count to check the current row count before adding the new row

Upvotes: 0

Hogan
Hogan

Reputation: 70523

It is not linked to the number of columns, except in so far as your memory has an upper limit so if you have so many columns you can't store the rows in memory you could get an out of memory error.

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1500495

I would expect that limit (which is 224) to be independent of the number of columns. I expect that it's just a single 32-bit integer internally is used to represent the row count as 24-bits and 8 bits are used for flags or something similar.

In practice, 16 million rows is going to take a long time to populate and a lot of memory... if you're in danger of hitting that limit, you should probably be rethinking how you're accessing data to start with.

Upvotes: 6

Related Questions