473,378 Members | 1,152 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Dataset Find Problem

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.
Nov 21 '05 #1
11 5764
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...

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Martin Horn" <ma****@mhorn.co.uk> wrote in message
news:6f*****************@newsfe1-gui.ntli.net...
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.

Nov 21 '05 #2
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...

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Martin Horn" <ma****@mhorn.co.uk> wrote in message
news:6f*****************@newsfe1-gui.ntli.net...
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.

Nov 21 '05 #3
you need to set up a primary key on your data table for the find to work.

"Martin Horn" <ma****@mhorn.co.uk> wrote in message
news:6f*****************@newsfe1-gui.ntli.net...
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.

Nov 21 '05 #4
you need to set up a primary key on your data table for the find to work.

"Martin Horn" <ma****@mhorn.co.uk> wrote in message
news:6f*****************@newsfe1-gui.ntli.net...
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.

Nov 21 '05 #5
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.
Nov 21 '05 #6
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.
Nov 21 '05 #7
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.
Nov 21 '05 #8
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.
Nov 21 '05 #9
Martin,

You can have a look at this page.

http://msdn.microsoft.com/library/de...ctiontopic.asp

I hope this helps?

Cor
Nov 21 '05 #10
Martin,

You can have a look at this page.

http://msdn.microsoft.com/library/de...ctiontopic.asp

I hope this helps?

Cor
Nov 21 '05 #11
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.

"Cor Ligthert" <no************@planet.nl> wrote in message
news:OH**************@TK2MSFTNGP12.phx.gbl...
Martin,

You can have a look at this page.

http://msdn.microsoft.com/library/de...ctiontopic.asp

I hope this helps?

Cor

Nov 21 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alex Ayzin | last post by:
Hi, I have a problem that might be easy to solve(possibly, I've just overlooked an easy solution). Here we go: I have a dataset with 2 datatables in it. Now, I need to do the following: if...
1
by: Bob Skutnick | last post by:
Help.... I've created an ADO.NET dataset in Visual Studio (a web project). I build the project and then try to create a Crystal Report using the dataset. When I try to use the ADO.NET dataset...
2
by: David Whitfield | last post by:
Hi All - I am an experienced ASP developer but am new to ASP.NET and the .NET framework and am trying to learn how to access datasets. When I try to build the following page, I get the errow...
2
by: Niyazi | last post by:
Hi, I have not understand the problem. Before all the coding with few application everything worked perfectly. Now I am developing Cheque Writing application and when the cheque is clear the...
1
by: HIK | last post by:
I am trying to write a class which has a function that loads a dataset, and performs and xslt tranformtion on the dataset and returns the resulting string. In asp.net 1.1 I was able to do most...
9
by: Miky | last post by:
I have the following problem: I am populating a dataset but, sometimes (NOT always), the NewRow method works like the Add method. SetRightDetail.RightDetail.Rows.Clear() For Each Right In...
16
by: Geoff Jones | last post by:
Hi Can anybody help me with the following, hopefully simple, question? I have a table which I've connected to a dataset. I wish to add a new column to the beginning of the table and to fill...
22
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
2
by: Carl Summers | last post by:
I have a table in an Access database that has no sort applied in Access. When I fill a dataset with data from that table (the entire one dimensional table) my dataset is sorted differently than...
4
by: Laurel | last post by:
Is there a way, in the debugger, to look at the contents of a dataset? I tried drilling down into my dataset and it's like exploring the registry! Anyway, I didn't find anything useful. The code...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.