Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select count(*) on dataTable... help

Status
Not open for further replies.

SidTheSquid

Programmer
Sep 25, 2002
34
0
0
CA
Hi, I have a myDataSet that has a dataTable tableSource. Its data from a web traffic log broken up in their repective columns.

I would like to create a vb.net function that takes in paramenters [columnName as string, tableSource as dataTable]
and returns a dataTable (or view). Its functionality would be equivalent to

"select columnName, count(*) from tableSource group by columnName"

In the end, I would like something like

ColumnName Count
IE6 345
IE5 35
Netscape 765
etc

I have no clue how to do this using dataview's filter, so any help you can give is super appreciated.
Thanks
Sid.
 
That should work. Only replace the count(*) with a count(fieldname) and you should be good to go. Are you getting an error when you execute this? Are you getting a resultset?

Eva
 
Yes, I am getting an error.
I have this:

Dim dv As New DataView
dv = myDataSet.Tables(tableNameSource).DefaultView
dv.RowFilter = "select browser_type, count(browser_type) from tableNameSource group by columnName"


(not exactly what I have but you get the idea)
I get the error

Syntax error: Missing operand after 'browser_type' operator

[SyntaxErrorException: Syntax error: Missing operand after 'browser_type' operator.]
System.Data.ExpressionParser.Parse() +2753
System.Data.DataExpression..ctor(String expression, DataTable table, Type type) +149
System.Data.DataView.set_RowFilter(String value) +150
....

I wanted to make somewhat of an sql query to a dataTable and not a database, and i find that the dataview is explicit in the rows you want to filter out.

So if you know how... let me know :)
Thanks
 
I'm no .NET wizard but I am some-what funtional in it. Could it be caused because the Column you create by the Count() doesn't have a Name and .Net is looking for one?

how about

dv.RowFilter = "select browser_type, count(browser_type) as Browser_Type_Count from tableNameSource group by columnName"



"Shoot Me! Shoot Me NOW!!!"
- Daffy Duck
 
It sounded like a good idea, but unfortunately it still doesnt work... I get the exact same error as before.

Any more suggestions?

 
Hi,

Try posting ur query in Visual Basic.Net forum forum796

Sunil

Sunil
 
I just noticed that your group by contains a diffrent object than your select list group by columnName, try group by Browser_Type.

"Shoot Me! Shoot Me NOW!!!"
- Daffy Duck
 
nope... it was just written like that here... :(
Still getting the same error.

Whoever can solve it gets a little star :)


btw: sorry for posting here... just realized that is not the correct place.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top