Home All Groups Group Topic Archive Search About

Filtering a uniqueidentifier column in a DataView / DataTable.Select method

Author
20 Mar 2006 8:15 AM
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

Author
20 Mar 2006 8:41 AM
Cor Ligthert [MVP]
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/default.asp?url=/library/en-us/cpref/html/frlrfsystemguidclassctortopic2.asp

I hope this helps,

Cor

Show quote
"Dirk" <iqs@newsgroups.nospam> schreef in bericht
news:%23aRprZ$SGHA.5108@TK2MSFTNGP11.phx.gbl...
> 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
Author
20 Mar 2006 9:43 AM
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

Cor Ligthert [MVP] wrote:
Show quote
> 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/default.asp?url=/library/en-us/cpref/html/frlrfsystemguidclassctortopic2.asp
>
> I hope this helps,
>
> Cor
>
> "Dirk" <iqs@newsgroups.nospam> schreef in bericht
> news:%23aRprZ$SGHA.5108@TK2MSFTNGP11.phx.gbl...
>> 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
>
>
Author
20 Mar 2006 3:05 PM
Sericinus hunter
Dirk wrote:
> 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.

AddThis Social Bookmark Button