Solved

dataset find guid by column value

Posted on 2007-04-03
1
322 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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

627 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