473,398 Members | 2,812 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,398 software developers and data experts.

DataRowCollection.Find Method

Hello,

I am trying to use the find method to locate a particular record in a
table. The code is :
object[]findTheseVals = new object[2];
findTheseVals[0] = station_ID; // an integer
findTheseVals[1] = dt; // a datetime
DataRow foundRow = dsStationDays.Tables["StationDays"].Rows.Find(
findTheseVals);

It is virtually verbatim from the help file. The StationDays table has a
primary key on an integer and datetime field combination, but I get a
[MissingPrimaryKeyException: Table doesn't have a primary key.] exception
when I execute the code. I have included the sql below that creates the
table:

CREATE TABLE [dbo].[StationDays] (
[Station_ID] [int] NOT NULL ,
[Day] [smalldatetime] NOT NULL ,
[Range] [float] NULL ,
[HighTide] [float] NULL ,
[LowTide] [float] NULL ,
[HighTime] [smalldatetime] NULL ,
... many more ...
[MoonSet] [smalldatetime] NULL ,
[MoonPhase] [float] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [dbo].[StationDays] WITH NOCHECK ADD
CONSTRAINT [PK_StationDays] PRIMARY KEY CLUSTERED
(
[Station_ID],
[Day]
) ON [PRIMARY]
GO

CREATE UNIQUE INDEX [StationDay] ON [dbo].[StationDays]([Station_ID],
[Day]) ON [PRIMARY]
GO

I'm not clear if I have an sql problem, or a csharp problem, but
hopefully someone here can help me.

Thanks

Marc Pelletier
Nov 16 '05 #1
4 5571

You must register those primary eys with your DataTable.

for example:

myDataTable.PrimaryKey = new DataColumn[] {
myDataTable.Columns["Station_ID"], myDataTable.Columns["Day"] };
Nov 16 '05 #2
Marc,

Did you ever look at the Dataview.find method, you see it seldom in these
newsgroups, however it is in my opinion very fine to use.

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

I hope this helps?

Cor
Nov 16 '05 #3
"=?Utf-8?B?TXJOb2JvZHk=?=" <Mr******@discussions.microsoft.com> wrote in
news:A2**********************************@microsof t.com:
myDataTable.PrimaryKey = new DataColumn[] {
myDataTable.Columns["Station_ID"], myDataTable.Columns["Day"] };


That works. Thank you very much.

Marc Pelletier
PS are you related to the Mr Nobody who spills all the milk and dumps the
Lego on the floor at my house?
Nov 16 '05 #4
"Cor Ligthert" <no************@planet.nl> wrote in
news:Oz**************@TK2MSFTNGP11.phx.gbl:
Did you ever look at the Dataview.find method, you see it seldom in
these newsgroups, however it is in my opinion very fine to use.

http://msdn.microsoft.com/library/de...y/en-us/cpref/
html/frlrfsystemdatadataviewclassfindtopic.asp


Thanks for reminding me about the DataView, I found it too painful to use
earlier, but I should revisit the topic.

cheers

Marc Pelletier
Nov 16 '05 #5

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

Similar topics

1
by: Derrick | last post by:
Hi all, I've been trying to understand exactly how to insert a newly created DataRow into a DataRowCollection at a specified row value without much luck. At first I was just appending the...
2
by: Scott Adams | last post by:
When calling the Find function of a DataRowCollection, one has two options: Overloads Public Function Find(ByVal key As Object) As DataRow or Overloads Public Function Find(ByVal keys() As...
0
by: Steve Richter | last post by:
how do I sort the Rows DataRowCollection of a DataTable? I have sub classed the DataRow class and added the IComparable interface: public class ResultsTableRow : System.Data.DataRow,...
2
by: Bill Nguyen | last post by:
What do I need to do to add a row to a table with single column? I got the "mnarrowing conversion" ewrror mesage. Thanks Bill -----------------
2
by: George | last post by:
Hi, I have encountered the following problem. Say I have the following, DataGridView dgv; DataTable dt; OleDbDataAdapter oleDb_da; (bound to a OleDb data connection)
3
by: Carlos | last post by:
Hi all, I have 2 asp .net 2.0 projects currently being developed. One is in VB .Net and the other in C#. In the VB .Net project I can cross-reference a datatable object using the...
0
by: ileving | last post by:
Hi, my name is Iram. I'm upgrading my winform application which was developed in .NET 1.1 to .NET 2. There is a code section that works well in .NET 1.1, but in .NET 2 raises an Exception...
5
gekko3558
by: gekko3558 | last post by:
I am writing a simple binary search tree (nodes are int nodes) with a BSTNode class and a BST class. I have followed the instructions from my C++ book, and now I am trying to get a remove method...
2
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double)...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.