the best way to set the primary key in a datatable or dataset

P

Peted

Hi

im hoping someone can provide or point to an code example of the best
(ie easiest quickest minimal code) way of setting the primary key of a
datatable or dataset targeted to .Net 3.5.

The dataset/datatable would either be already existing OR at the point
of created when the primary key is set

The code examples i found on the net seem to be overly convoluted for
what i would think was something easily set using a property or
something, or am i silly to think this

Peted
 
A

Alberto Poblacion

im hoping someone can provide or point to an code example of the best
(ie easiest quickest minimal code) way of setting the primary key of a
datatable or dataset targeted to .Net 3.5.

The dataset/datatable would either be already existing OR at the point
of created when the primary key is set

The code examples i found on the net seem to be overly convoluted for
what i would think was something easily set using a property or
something, or am i silly to think this

It's reasonably easy. You just add the column or columns to the
PrimaryKey property of the datatable:

theDataTable.PrimaryKey = new DataColumn[]{theDataTable.Columns[0]};
 

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