Solved

dataset find guid by column value

Posted on 2007-04-03
1
311 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
1 Comment
 
LVL 25

Accepted Solution

by:
dstanley9 earned 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

776 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