SQL in VB.NET Question

Borgi

New member
Joined
Feb 10, 2006
Messages
3
Programming Experience
10+
I'm sure that this is a simple question, but just having started with sql, I'm kind of lost..

the table looks like this:
id int, id2 int, name char, ew int, date char
for each date there is (at least) one row of each id, sometimes multiple.

What I need is the sum of ew for a give id for each date.

"select sum(ew) from x_world_master and id=" +str(id(iSp)) +"and date="+date(ida)

I have multiple id's for which I need to run this query. The query works fine and returns exactly what I expect in sql - sum(ew) for each date.

I can do

con.Open()
cmd.Connection = con
cmd.CommandText = ewquery
ew(iSp, iDa) = cmd.ExecuteScalar()
con.Close()

which works fine for each iSp (60) and each iDa(30), but this means opening and closeing the db 1800 times, which is not the smartest thing to do.

I could change it to

"select sum(ew) from x_world_master and id=" +str(id(iSp)) +"group by datum"

which gives me:

+---------+
| sum(ew) |
+---------+
| 183 |
| 201 |
| 213 |
| 218 |
| 222 |
| 230 |
| 253 |
| 255 |
| 258 |
| 259 |
| 263 |
| 263 |
| 263 |
| 263 |
| 263 |
| 263 |
| 263 |
| 263 |
| 265 |
| 265 |
+---------+

How do I get this into variables in vb.net? (I told you it's a simple question)

Or is there a smarter way of doing this altogether?

thanks.
--bjorn
 
Back
Top