dataTable.Compute("Count(GuidCol)", "") generates Exception

G

Guest

Hi,

I have a datatable that has three columns each of data type Guid. (which I
have just changed from previously being Integers)

In the past I have used :

dataTable.Compute("Count(Col1)", "Col1=5") - which worked fine

Now having changed the data types to Guids I get an exception when I use:

dataTable.Compute("Count(Col1)",
"Col1='00000000-0000-0000-0001-000000000032'")

(also generates exception for:

dataTable.Compute("Count(Col1)", "") - so the problem is not with the
filter expression.

The error is:
Message="Invalid usage of aggregate function Count() and Type: Guid."
Source="System.Data"

Does anyone know how to get this working please?

thanks,

Giles







generates Exception

I would like to use th

Invalid usage of aggregate function Count() and Type: Guid.
 
S

Steven Cheng[MSFT]

Hi Giles,

Welcome to ADO.net newsgroup.
As for the problem on use DataTable's filter functions (compute or Select
methods...) with Guid column, it is actually due to the DataTable's sql
expression engine only support some basic types such as numeric , string
text .... As for Guid, the DataTable's build-in filtering engine can not
support those sql experssion on Guid type column. Currently based on my
testing, one possible means is to use a string type column which contains
the Guid's string text (through Guid.ToString()), we can perform normal
sql filtering operations on string type columns correctly... So I'm not
sure whether using a string column in your DataTable instead of the Guid
column is possible, if not (e.g your datatable is filled by DataAccessing
from backend database...), we may need to implement our own function which
loop the DataTable rows to find the unique row....

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)





--------------------
| Thread-Topic: dataTable.Compute("Count(GuidCol)", "") generates Exception
| thread-index: AcX5B5WxUTxhEULOTXO/wcNtk6nyjA==
| X-WBNR-Posting-Host: 80.3.160.7
| From: =?Utf-8?B?R2lsZXNU?= <[email protected]>
| Subject: dataTable.Compute("Count(GuidCol)", "") generates Exception
| Date: Sun, 4 Dec 2005 11:19:02 -0800
| Lines: 40
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.adonet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.adonet:117211
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Hi,
|
| I have a datatable that has three columns each of data type Guid. (which
I
| have just changed from previously being Integers)
|
| In the past I have used :
|
| dataTable.Compute("Count(Col1)", "Col1=5") - which worked fine
|
| Now having changed the data types to Guids I get an exception when I use:
|
| dataTable.Compute("Count(Col1)",
| "Col1='00000000-0000-0000-0001-000000000032'")
|
| (also generates exception for:
|
| dataTable.Compute("Count(Col1)", "") - so the problem is not with the
| filter expression.
|
| The error is:
| Message="Invalid usage of aggregate function Count() and Type: Guid."
| Source="System.Data"
|
| Does anyone know how to get this working please?
|
| thanks,
|
| Giles
|
|
|
|
|
|
|
| generates Exception
|
| I would like to use th
|
| Invalid usage of aggregate function Count() and Type: Guid.
|
 
G

Guest

Thanks Steven, for the reply,

Is the column paramater in the Count() function actually used for any
purpose? - ie if I set up another column in the table say a string - does the
value of the strings need to be unique or will it still count all the rows if
the strings are the same. - if so why have a parameter?

Is the behaviour with the GUIDs by design - or is it a bug - are there
likley to be any fixes for this?

Cheers,

Giles.
 
K

Kevin Yu [MSFT]

Hi Giles,

As far as I know, the aggregate functions only support simple data types,
which does not include GUID. If you set up another string column include
the GUID values, it needn't to be unique.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
V

Vasco Veiga [MS]

It is by design.

Guid (System.Guid) columns are stored as objects, and when asked by the
expression evaluator to evaluate the aggregate COUNT they "don't know" how
to do it.

You can use SqlGuid columns (preferred) or add a calculated column that
converts Guid to SqlGuid, and count it.

dt.Columns.Add( "ugly_sqlguidcol_hack"
, typeof( SqlGuid )
, "CONVERT( guidcol,
'System.Data.SqlTypes.SqlGuid' )" );
dt.Compute( "COUNT( ugly_sqlguidcol_hack )" );


--VV [MS]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top