Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

dataset find guid by column value

Posted on 2007-04-03
1
Medium Priority
?
324 Views
Last Modified: 2013-12-16
I have a windows app vb.net 2005.

I want to find a guid by passing in a value and a column name

countries table
GUID
name
longname

I want to do something like
guid=ctable.findGUID("name", "USA")

or
guid=ctable.findGUID("longname", "United States")
0
Comment
Question by:jackjohnson44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 25

Accepted Solution

by:
dstanley9 earned 2000 total points
ID: 18845216
try this:

public Guid FindGuid(DataTable table, string column, string value)
{
   // see if the column exists
   if(table.Columns[column] == null)
    throw new Application Exception("Column " + column + " does not exist.");

   DataRow[] rows = table.Select(column + " = '" + value + "'");
   if(rows.Length == 0) // no match found
      return null;
   if(rows.Length > 1) // multiple matches found
      throw new Application Exception("Too many matches.");
   
   return (Guid)rows[0]["GUID"];
}
0

Featured Post

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

671 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question