473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Select Query from SQL to VB.NET - using SUM

Hi people,

I have a question that nobody as of yet has been able to answer for me.

I have an SQL query which is:

SELECT sum(TimeSpent) AS TimeSpentDWR
FROM DWRWork
WHERE DWRID = @DWRID

When I provide the parameter, it sums the timespent field OK.

Now in VB.Net (2003) I am unable to do this. I have created a DataAdapter
with a select command of above, and generated the DataSet.
Within my form load, I have the line:
SqlSelectCommand11.Parameter("@DWRID").Value = lblDWRID.text

When I try to run the form, I get "System Error" from debug, but if I run
the form without debugging, I then get the error within the program telling
me that the parameter @DWRID has not been provided.

Does anybody have any solution to this? I need to sum two fields up onto
one form, and at the moment I can't even get one to work - I'm new to
programming and this is my first project, so is getting a bit depressing at
the moment as it's been a problem for a few months!

Thanks for your help.
Nov 22 '05 #1
2 7330
Hi,

Two possibilities come to mind offhand:

1) Have you added the parameter itself (as in using
SqlSelectCommand11.Parameters.Add())?
2) What is the datatype of your parameter? It might (though somewhat
unlikely) be something along the lines that no type was specified or it's
otherwise expecting character data, but SQL Server's parameter type should
be int. It's probably not this specific issue, but maybe that will give a
little idea...

- John

"VBNewbie" <VB******@discussions.microsoft.com> wrote in message
news:68**********************************@microsof t.com...
Hi people,

I have a question that nobody as of yet has been able to answer for me.

I have an SQL query which is:

SELECT sum(TimeSpent) AS TimeSpentDWR
FROM DWRWork
WHERE DWRID = @DWRID

When I provide the parameter, it sums the timespent field OK.

Now in VB.Net (2003) I am unable to do this. I have created a DataAdapter
with a select command of above, and generated the DataSet.
Within my form load, I have the line:
SqlSelectCommand11.Parameter("@DWRID").Value = lblDWRID.text

When I try to run the form, I get "System Error" from debug, but if I run
the form without debugging, I then get the error within the program
telling
me that the parameter @DWRID has not been provided.

Does anybody have any solution to this? I need to sum two fields up onto
one form, and at the moment I can't even get one to work - I'm new to
programming and this is my first project, so is getting a bit depressing
at
the moment as it's been a problem for a few months!

Thanks for your help.

Nov 22 '05 #2
Hi John,

Thanks for your reply.

I sat down and figured this out yesterday afternoon (well I think I've
figured it).

The error wasn't coming from the sum - the error was coming from when the
dataAdapters fill.
I generated a new dataSet for the sum tables, and then created a new sub in
the code called "RefreshTime" with the parameters matching the label text
showing the ID fields, and then clearing the dataSet, and filling the two sum
DataAdapters.

Instead of kicking this off at form load time (which was causing the
problem), I run this sub when the child dataGrid row is changed.

I think the problem was because it was running at form load time, the
parameters were looking at the label text for their value - these hadn't been
filled yet.

As said earlier, not sure whether this is the correct way, but it's working!!


"John Spiegel" wrote:
Hi,

Two possibilities come to mind offhand:

1) Have you added the parameter itself (as in using
SqlSelectCommand11.Parameters.Add())?
2) What is the datatype of your parameter? It might (though somewhat
unlikely) be something along the lines that no type was specified or it's
otherwise expecting character data, but SQL Server's parameter type should
be int. It's probably not this specific issue, but maybe that will give a
little idea...

- John


Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: John Fabiani | last post by:
Hi, I'm a newbie and I'm attempting to learn howto create a select statement. When I use >>> string1='18 Tadlock Place' >>> cursor.execute("SELECT * FROM mytest where address = %s",string1) All...
4
by: psql-mail | last post by:
I am running a SELECT to get all tuples within a given date range. This query is much slwoer than i expected - am i missing something? I have a table 'meta' with a column 'in_date' of type...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
1
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
4
by: Polly | last post by:
I had a macro that ran a parameter query and created and opened an Excel file with the system date as part of the file name, but I had to change the file name by hand. So I converted the macro to...
2
by: Pavel Stehule | last post by:
Hello, Pg make query 1. and 2. very fast (use index), but for query 3. dont use index. I can solve its using select union, but I readed so pg 7.5 don't problem with OR operator. I use cvs pg. I...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
5
by: parwal.sandeep | last post by:
Hello grp! i'm using INNODB tables which are using frequently . if i fire a SELECT query which fetch major part of table it usually take 10-20 seconds to complete. in mean time if any UPDATE...
4
by: The.Daryl.Lu | last post by:
Hi, Have a bit of a problem... I've created a form in Access and will use the form for a user to query a table based on the selected fields. The problem lies in that I was using checkboxes for...
3
by: RAG2007 | last post by:
I'm using the QueryDef and Execute method to update a record in my MySQL backend. Problem: When the Passthrough update query is defined using QueryDef, it becomes a select query, and I cannot use...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.