Primary key Usage

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello:

Even after I set the primary key of a table in a data set by:

DataSet11.Tables("DISP_STATUS").PrimaryKey = New DataColumn()
{DataSet11.Tables("DISP_STATUS").Columns("D_Stat_CD_C")}

when I search for a row by the key,

Dim dr As DataRow = DataSet11.Tables("DISP_STATUS").Rows.Find(New Object()
{dataKey})

I get an exception, "System.Data.MissingPrimaryKeyException: Table doesn't
have a primary key."

What am I doing wrong?

Thanks for your help.

Venki
 
Venki,

When you have this kind of problems than start with making it yourself easy
to find the error
Even after I set the primary key of a table in a data set by:

DataSet11.Tables("DISP_STATUS").PrimaryKey = New DataColumn()
{DataSet11.Tables("DISP_STATUS").Columns("D_Stat_CD_C")}

dim myTable as DataTable = Dataset11.Tables("DISP_STATUS")
'This is the same table, only another reference to it.

And than you can just follow the sample on this page.

http://msdn.microsoft.com/library/d...rfsystemdatadatatableclassprimarykeytopic.asp

Probably a good exercise to do it yourself.

I hope this helps,

Cor
 
Back
Top