Primary key Usage

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
 
C

Cor Ligthert [MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top