PC Review


Reply
Thread Tools Rate Thread

DataRowCollection::Find problem

 
 
Tom Archer
Guest
Posts: n/a
 
      1st Aug 2003
In using the DataRowCollection::Find with the
NorthWind/Employees table, I'm getting an exception
stating that the table doesn't contain a primary key -
which it does (EmployeeID). Has anyone else run into
problems with this method?
 
Reply With Quote
 
 
 
 
Carl Prothman [MVP]
Guest
Posts: n/a
 
      2nd Aug 2003
"Tom Archer" <(E-Mail Removed)> wrote
> In using the DataRowCollection::Find with the
> NorthWind/Employees table, I'm getting an exception
> stating that the table doesn't contain a primary key -
> which it does (EmployeeID). Has anyone else run into
> problems with this method?


Tom,
In order to use the Find method, the DataTable object to which the
DataRowCollection object belongs to must have at least one column
designated as a primary key column.
http://msdn.microsoft.com/library/en...rykeytopic.asp

See the PrimaryKey property for details on creating a PrimaryKey column,
or an array of DataColumn objects when the table has more than one primary key.
http://msdn.microsoft.com/library/en...findtopic2.asp

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.able-consulting.com




 
Reply With Quote
 
Tom Archer
Guest
Posts: n/a
 
      2nd Aug 2003
Thanks Carl.

Just to clarify that I'm understanding this correctly:

ADO.NET can't figure out that the underlying table has a
primary key so I must explicitly tell it which column is
the primary key?
 
Reply With Quote
 
Carl Prothman [MVP]
Guest
Posts: n/a
 
      2nd Aug 2003
"Tom Archer" <(E-Mail Removed)> wrote
> Just to clarify that I'm understanding this correctly:
>
> ADO.NET can't figure out that the underlying table has a
> primary key so I must explicitly tell it which column is
> the primary key?
>


Tom,
For an untyped DataSet, the primary key information is NOT filled in.
In this case, you'll need to specify which column(s) is the primary key.

However, for a Typed DataSet, then the primary key information
is filled in for you.

e.g.

// Untyped DataSet
DataSet dataSet = new DataSet();
sqlDataAdapter1.Fill(dataSet, "Employees");
int count1 = dataSet.Tables["Employees"].PrimaryKey.Length;
// count1 = 0

// Typed DataSet
EmployeesDataSet employeeDataSet = new EmployeesDataSet();
sqlDataAdapter1.Fill(employeeDataSet.Employees);
int count2 = employeeDataSet.Employees.PrimaryKey.Length;
// count2 = 1

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.able-consulting.com




 
Reply With Quote
 
Tom Archer
Guest
Posts: n/a
 
      2nd Aug 2003
That was the missing piece to the puzzle. Thanks again,
Carl.
 
Reply With Quote
 
Kathleen Dollard
Guest
Posts: n/a
 
      2nd Aug 2003
Tom,

Try using MIssingSchemaAction = ...AddWithKey on your DataAdapter.

--
Kathleen (MVP-VB)



"Tom Archer" <(E-Mail Removed)> wrote in message
news:044c01c3586b$a56d3b10$(E-Mail Removed)...
> In using the DataRowCollection::Find with the
> NorthWind/Employees table, I'm getting an exception
> stating that the table doesn't contain a primary key -
> which it does (EmployeeID). Has anyone else run into
> problems with this method?



 
Reply With Quote
 
Tom Archer
Guest
Posts: n/a
 
      2nd Aug 2003
>-----Original Message-----
>Tom,
>
>Try using MIssingSchemaAction = ...AddWithKey on your

DataAdapter.

Works like a charm. Thanks Kathleen.
 
Reply With Quote
 
Carl Prothman [MVP]
Guest
Posts: n/a
 
      2nd Aug 2003
"Carl Prothman [MVP]" <(E-Mail Removed)> wrote
> For an untyped DataSet, the primary key information is NOT filled in.
> In this case, you'll need to specify which column(s) is the primary key.
>


Or set the MissingSchemaAction before the Fill method:
sqlDataAdapter1.MissingSchemaAction = MissingSchemaAction.AddWithKey

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.able-consulting.com




 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Performance of DataRowCollection.Find() ? AAA Microsoft ADO .NET 2 29th Jan 2009 05:16 PM
DataRowCollection.Find Scott Adams Microsoft Dot NET 2 7th Jul 2005 10:56 PM
DataRowCollection.Find Method Marc Pelletier Microsoft C# .NET 4 7th Jan 2005 03:53 AM
DataRowCollection.Find Method throws invalidcastexception Sagaert Johan Microsoft Dot NET Compact Framework 1 31st Dec 2004 12:40 AM
Bug in DataRowCollection.Find() Robert van Poelgeest Microsoft ADO .NET 0 19th Oct 2003 08:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:54 AM.