Click here to Skip to main content
15,886,584 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can i get the result of my sql sum query into a textbox ? heres my code: edited: i need to get the sql sum result to text112.


What I have tried:

If rs3.State <> 0 Then rs3.Close
    rs3.Open "select sum(TotalHours) as thrs from tbldwardetails where employeesid  =" & Val(empids) & " And dwardate=" & Val(dwardate), db, 3, 3
    If rs3.RecordCount <> 0 Then
    Text112.Text = rs3!thrs
    Else

    End If
Posted
Updated 8-Aug-17 18:22pm
Comments
Michael_Davies 9-Aug-17 1:50am    
Use the debugger to check the results as it may be that the query is not returning a value, I think dates for Access need to be enclosed by #'s.

rs3.Open "select sum(TotalHours) as thrs from tbldwardetails where employeesid =" & Val(empids) & " And dwardate=#" & Val(dwardate) & "#", db, 3, 3

Also not sure why you you Val() the date, the date in this case is not a number but a string.

1 solution

Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900