Solved

dataset find guid by column value

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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

739 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