473,396 Members | 1,918 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,396 software developers and data experts.

How can I find a DataRow in a DataSet by it's PrimaryKey value?(C++/CLI)

How can I find a DataRow in a DataSet by it's PrimaryKey value? This
would be similar to an SQL statement such as "SELECT * FROM MyTable
WHERE MyIndex = 2"...

In the following code I've tried to do this but "dataSet-
>Tables["GpsData"]->Rows->Find" returns a nullptr every time...
/* C++/CLI Code Sample (doesn't work) */

cli::array<System::Data::DataColumn ^^colarray =
gcnew cli::array<System::Data::DataColumn ^>(1);
colarray[0] =
dataSet->Tables["GpsData"]->Columns["Distance"];
dataSet->Tables["GpsData"]->PrimaryKey =
colarray;

DataRow ^drow =
dataSet->Tables["GpsData"]->Rows->Find(
dataSet->Tables["CisData"]->Rows[i]["GpsIndexFK"]
);

if(drow != nullptr)
System::Windows::Forms::MessageBox::Show(
safe_cast<Int32 ^>(drow["Index"])->ToString()
);
Jan 3 '08 #1
2 3167
go****@robertbennett.us wrote:
How can I find a DataRow in a DataSet by it's PrimaryKey value? This
would be similar to an SQL statement such as "SELECT * FROM MyTable
WHERE MyIndex = 2"...
Use DataTable.Select - you can pass a filter string (basically, the
expression from the Where clause of your SQL) to select the rows you want.
You'll get back an array of DataRows.

-cd

Jan 3 '08 #2
On Jan 3, 4:38*pm, "Carl Daniel [VC++ MVP]"
<cpdaniel_remove_this_and_nos...@mvps.org.nospamwr ote:
goo...@robertbennett.us wrote:
How can I find a DataRow in a DataSet by it's PrimaryKey value? This
would be similar to an SQL statement such as "SELECT * FROM MyTable
WHERE MyIndex = 2"...

Use DataTable.Select - you can pass a filter string (basically, the
expression from the Where clause of your SQL) to select the rows you want.
You'll get back an array of DataRows.

-cd
You're a life saver. I'd actually already wrote a function to scan a
column for a value because I hadn't realized this method existed.

Thanks
Jan 4 '08 #3

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

Similar topics

0
by: nima | last post by:
Hi I have two tables in my database. PRODUCT and PRODUCT_GROUP. PRODUCT has a foreign key to PRODUCT_GROUP. I generated a typed dataset using VS.net and added a relationship between the two...
1
by: thomaz | last post by:
Hi; My code below doesn´t work well in windows 98 only. I use them in windows XP and it´s OK. thisBuilder = new OleDbCommandBuilder (thisAdapter); thisDataSet = new DataSet ();
17
by: Justin Emlay | last post by:
I'm hopping someone can help me out on a payroll project I need to implement. To start we are dealing with payroll periods. So we are dealing with an exact 10 days (Monday - Friday, 2 weeks). ...
4
by: Aaron Smith | last post by:
Dim dv As DataView = New DataView(FacilitiesDS1.Facilities, "", "ID ASC", DataViewRowState.CurrentRows) Dim iPos As Integer = dv.Find(dr.Item("ID")) Me.BindingContext(FacilitiesDS1,...
1
by: Lars E | last post by:
Hi all I have a small problem. I have a datatable with 8 columns. But it is only data in 5 of the columns. Data for the remaing 3 columns is in another dataset. I Want to run trough the...
1
by: Ryan Liu | last post by:
Hi, When my code run to DataRow.Delete() It throws: System.ArgumentOutOfRangeException: Non-negative number required. Parameter name: length at System.Array.Copy(Array sourceArray, Int32...
1
by: Arpan | last post by:
This is how I am dynamically adding a table to a DataSet: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) 'Create an empty DataSet Dim dSet As New DataSet ...
2
by: =?Utf-8?B?UmljaA==?= | last post by:
Greetings, I need to locate a row (or see if it exists) in a table contained in a dataset. The DataView.Find method seems to work OK for one criteria but I need to use 2 criterias. Is there...
1
by: =?Utf-8?B?Rm9lZg==?= | last post by:
I have a BindingSource with an underlying table with two primary keys. To set the position with one primary key works fine as shown in the code snippet below: Dim index As Integer =...
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
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:
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...
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
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
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...
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...

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.