Dataset Find Problem

  • Thread starter Thread starter Martin Horn
  • Start date Start date
M

Martin Horn

Hi,

I get a 'System.Data.MissingPrimaryKeyException' when running the follwing
code:-
StockListDataSet.Tables("Items").Rows.Find("12345")

Is there any way around this? Do I need to supply more information?

Thanks.
 
do you have a Key defined on the Items table? Also, since you're using a
StronglyTyped DataSet, - not sure you want to referencethe table with
"Items"... if the table name changes for some reason - you wont find out
until compile time when you get an error...
 
you need to set up a primary key on your data table for the find to work.
 
Thanks for the reply, as you have probably gathered I am quite new to this.
Maybe I should explain in more depth what I am trying to do.
do you have a Key defined on the Items table?

I have now, and that has removed the error, but the code didn't produce the
result I was after anyway.
Also, since you're using a
StronglyTyped DataSet, - not sure you want to referencethe table with
"Items"... if the table name changes for some reason - you wont find out
until compile time when you get an error...

Let's assume for the moment that the table name won't change, because I'm
not entirely sure what the alternative way of referencing it is.

In simple terms this is the situation:-

I have a Dropdown combo box bound to a datasource with datamember set to
"Description"
and a Textbox bound to the "ProductCode" field of the same datasource.

When I select a new item in the combo box the ProductCode textbox updates,
which is what I want.

However I also want to be able to type in a product code and when I press
enter I would like to search the dataset for a match and set the dataset
position to reflect this, which should update the combobox to the
corresponding description.

I hope this newbie rambling makes some kind of sense.

Thanks.
 
I have found a solution that works.

Dim pos As DataRow
pos = DataSet1.Tables("Items").Rows.Find(sender.text)
DataConnector1.Position = DataSet1.Tables("Items").Rows.IndexOf(pos)

Probably quite the wrong way to go about it, but it works so it'll do for
now.
 
I'm not entirely sure if it helps or not, as I seem to have gaping great
holes in my knowledge of database handling. But the main thing is that, for
the moment I have cobbled together a working solution, and I think that's
the best I can hope for in the short term.

I must be slowly improving though, because when I tackled this 6 months ago
I gave up completely, maybe there's light at the end of the tunnel after all
:)

Thanks everyone for your help and comments.
 

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

Back
Top