Solved

dataset find guid by column value

Posted on 2007-04-03
1
305 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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now