Reputation: 1
my Table Kategorija
has Primary Key (IDKategorije
)
When I use a data set, like in a part of my code:
string s = textBox1.Text ;
DataRow dRow2 = ds1.Tables["Kategorija"].Rows.Find(s);
I get an error :
Table has no Primary Key
How is that?
Upvotes: 0
Views: 470
Reputation: 19150
You need to set the PrimaryKey property on the DataTable first. See:
http://msdn.microsoft.com/en-us/library/ydd48eyk.aspx
Upvotes: 0
Reputation: 21275
You can only use DataTable.Rows.Find() if you defined a primary key for that DataTable. Take a look: http://msdn.microsoft.com/en-us/library/system.data.datatable.primarykey.aspx
Upvotes: 0
Reputation: 56934
That is, because your DataTable
has no primary key defined. This has nothing to do with the Table in your database, but I guess that the Find
method on the Rows
collection needs a primary key constraint on the DataTable
in order to work.
More information regarding the PrimaryKey
property can be found here
Next to that, I think you're better of using a Typed Dataset.
Upvotes: 2