How do I use the find method of a datatable with a compound key?

I am working on a windows form application. How do i use the find method of a datatable to find a row if the datatable has a compound key?

Table Structure Col A, Col B, Col C

Col A and Col B make up the compound key. I want to find the row where the value in Col A is 6 and Col B is 5


There is an overload that you can use to pass in two different values to the find method. Here is the MSDN doc.

So you would most likely be doing something like.


When you "set" the Primary key of the datatable, the parameter value is an array of DataColumns...

if your datatable is in variable dt...,

dt.PrimaryKey = new DataColumn[] {dt.Columns["ColA"], dt.Columns["ColB"]};

Then pass an array of object vlaues to the Find() method

object[] keyVals = new object[] {6, 5};
DataRow dr = dt.Rows.Find(keyVals);

or, just

DataRow dr = dt.Rows.Find(new object[] {6, 5});

Need Your Help

python mysqldb inserting NULL using a prepared statement

python insert null prepared-statement mysql-python

I'm having issues with python when I try to insert NULL into a field using a prepared mysqldb statement. The problem is that python doesn't like NULL without quotes and then MySQL doesn't like 'NU...

how to find php.ini in php5.3

php apache sockets

i'm having a problem when i'm create socket program.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.