Filtering a uniqueidentifier column in a DataView / DataTable.Selectmethod

  • Thread starter Thread starter Dirk
  • Start date Start date
D

Dirk

Hi,

I made heavy use of unique identifier columns. I load a bunch of data in
a dataset and want to make some queries on that data (off line). For
that, I often need to filter in the uniqueidentifier columns.

What is the appropriate way to do this, so that I get the best
performance? Do I need have to use the Convert syntax?

DataRow[] rows = m_dt.Select("Convert(myGuidCol, 'System.String') = '" +
myGuid.ToString() + "'");

Or is there a better way?

best regards

Dirk
 
Hello Cor,

My problem was not how to get a Guid Object. The question was how to
build the filter string correctly.

I tried the following and it works well:

DataRows[] rows = myDataTable.Select("MyGuidCol = '" + myGuid + "'");

where myGuid is an System.Guid object.

So I will use this solution, i hope its the best one.

Thank you for your answer.

regards

Dirk
Dirk,

Why do you not construct a new guid with your string value to compare.
(be aware to set this in a try catch block for wrong guid strings)

http://msdn.microsoft.com/library/d...cpref/html/frlrfsystemguidclassctortopic2.asp

I hope this helps,

Cor

Dirk said:
Hi,

I made heavy use of unique identifier columns. I load a bunch of data in a
dataset and want to make some queries on that data (off line). For that, I
often need to filter in the uniqueidentifier columns.

What is the appropriate way to do this, so that I get the best
performance? Do I need have to use the Convert syntax?

DataRow[] rows = m_dt.Select("Convert(myGuidCol, 'System.String') = '" +
myGuid.ToString() + "'");

Or is there a better way?

best regards

Dirk
 
Dirk said:
Hello Cor,

My problem was not how to get a Guid Object. The question was how to
build the filter string correctly.

I tried the following and it works well:

DataRows[] rows = myDataTable.Select("MyGuidCol = '" + myGuid + "'");

where myGuid is an System.Guid object.

Is the above a typo?
Anyway, I think Select("MyGuidCol='" + myGuid.ToString() + "'") is
a way to go.
 
Back
Top