|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Filtering a uniqueidentifier column in a DataView / DataTable.Select methodHi,
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,
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 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 > > Dirk wrote:
> Hello Cor, Is the above a typo?> > 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. Anyway, I think Select("MyGuidCol='" + myGuid.ToString() + "'") is a way to go. |
|||||||||||||||||||||||