473,763 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataRowCollecti on.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.T ables["StationDay s"].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
[MissingPrimaryK eyException: 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 5598

You must register those primary eys with your DataTable.

for example:

myDataTable.Pri maryKey = new DataColumn[] {
myDataTable.Col umns["Station_ID "], myDataTable.Col umns["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******@discu ssions.microsof t.com> wrote in
news:A2******** *************** ***********@mic rosoft.com:
myDataTable.Pri maryKey = new DataColumn[] {
myDataTable.Col umns["Station_ID "], myDataTable.Col umns["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******** ******@TK2MSFTN GP11.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/frlrfsystemdata dataviewclassfi ndtopic.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
415
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 collection with the Add method. That worked fine, but not the InsertAt method. It always inserts the new row at the end, just like Add did. Thanks for wathever help you can give. Cheers, Derrick
2
5685
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 Object) As DataRow This function is easy to use if the primary key of your DataTable consists of only one field. How can you use the Find functions if the primary key consists of two database fields (composite key)?
0
2829
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, IComparable { public ResultsTableRow( DataRowBuilder builder ) : base( builder ) {
2
4268
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
3386
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
7726
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 datatable.rows.item(i).item(j) , but in the C# project I can not do it. That is, I do get: error 'System.Data.DataRowCollection' does not contain a definition for 'Item' They are running under the same development evironment. (i.e. Asp .Net 2.0)
0
1159
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 of:{"Object reference not set to an instance of an object."} System.Exception {System.NullReferenceException} The code is: DataRowCollection rc; DataRow newSearchRow; rc = searchQuestions.Rows; newSearchRow = searchQuestions.NewRow();
5
5274
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 working. But before I get to the remove, I need to get my find method working. Basically, I am trying to get a "find" method working that will search for a giving int value, and return the node with that value. I have designed my current find with the...
2
6658
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) Location: class Week5MortgageGUI Week5MortgageLogic allint = logic.allInterest(amount, term, rate); Week5MortgageGUI.java:152:cannot find symbol symbol: method allInterest(double,double,double) Location: class Week5MortgageGUI
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10145
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.