Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / January 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
google@robertbennett.us - 03 Jan 2008 20:21 GMT
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()
    );
Carl Daniel [VC++ MVP] - 03 Jan 2008 21:38 GMT
> 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
google@robertbennett.us - 04 Jan 2008 14:43 GMT
On Jan 3, 4:38 pm, "Carl Daniel [VC++ MVP]"
<cpdaniel_remove_this_and_nos...@mvps.org.nospam> wrote:
> goo...@robertbennett.us wrote:
> > How can I find a DataRow in a DataSet by it's PrimaryKey value? This
[quoted text clipped - 6 lines]
>
> -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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.