如何将SQL总和查询的结果导入文本框? VB6 [英] How can I get the result of my SQL sum query into a textbox ? VB6

查看:198
本文介绍了如何将SQL总和查询的结果导入文本框? VB6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将我的sql sum查询结果导入文本框?继承我的代码:编辑:我需要将sql sum结果发送到text112。





我尝试了什么:



如果rs3.State<> 0然后rs3.Close 
rs3.Openselect sum(TotalHours)as trs from tbldwardetails where employeesid =& Val(empids)& 和dwardate =& Val(dwardate),db,3,3
如果rs3.RecordCount<> 0然后
Text112.Text = rs3!thrs
否则

结束如果

解决方案

< blockquote>不是你的问题的解决方案,但你有另一个问题。

永远不要通过连接字符串来构建SQL查询。迟早,您将使用用户输入来执行此操作,这会打开一个名为SQL注入的漏洞,这对您的数据库很容易并且容易出错。

名称中的单引号你的程序崩溃。如果用户输入像Brian O'Conner这样的名称可能会使您的应用程序崩溃,那么这是一个SQL注入漏洞,崩溃是最少的问题,恶意用户输入,并且它被提升为具有所有凭据的SQL命令。

SQL注入 - 维基百科 [ ^ ]

SQL注入 [ ^ ]

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

解决方案

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[^]


这篇关于如何将SQL总和查询的结果导入文本框? VB6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆