Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataTable.Rows.Find gives "Table doesn't have a primary key" error when table gets too big

Tags:

c#

Working with a .NET 3.5 project and I have a DataTable I fill from a MySQL table. The table contains an "email" column that I need to search on. I am explicitly setting the primary key, and the following code works fine until I get 422 or more rows in the table.

object[] searchfor = new object[] { row["email"] };
DataColumn[] pk = new DataColumn[] { dtAccounts.Columns["email"] };
dtAccounts.PrimaryKey = pk;
match = dtAccounts.Rows.Find(searchfor);

I thought maybe there was some bad data in the 422nd record, but have verified that's not the case. The error I get is "Table doesn't have a primary key", which it obviously does.

like image 997
PahJoker Avatar asked Dec 09 '25 08:12

PahJoker


1 Answers

My bad. I was filling my DataTable via web service, and once I got to 422 rows, the message size was too big and my DataTable never got filled. I just needed to increase the maxReceivedMessageSize value in my app.config file. Error message was less than helpful in this situation!

like image 179
PahJoker Avatar answered Dec 11 '25 22:12

PahJoker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!