变量中查询的存储结果 [英] Stored result of Query in a Variable

查看:52
本文介绍了变量中查询的存储结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友

我在我的旧项目中遇到问题,现在客户端要求的东西就像表中有100条记录一样我应该能够显示的数量在数据报告中被指定为主管的员工。

我正在尝试但无法显示记录数。我尝试这样的事情:

我正在使用带有ado的Access数据库。



Hello friends
I am facing a problem on my very old project where now the client is asking for something like if there are 100 records in a table and i should be able to display the number of employees whose designation is like "supervisors" on a data report.
I am trying but can not display the number of records. I try something like this:
I am using Access database with ado.

dim temp as string
temp = "select count(*) from employees where designation='" & cmbodesig.Text & "'", Con, adOpenDynamic, adLockPessimistic
DataReport1.Sections("Section2").Controls("Label5").Caption =temp



我在网上搜索了很多但没有结果

请帮帮我

谢谢

Sarfaraz


I searched a lot on the web but no results
Please help me
Thank you
Sarfaraz

推荐答案

你定义了查询,但是你从来没有运行它数据库或数据源。您需要运行查询才能获取数据。 Temp只是SQL字符串,您需要建立与数据库的连接,然后创建SQL命令对象并运行它。这将返回具有单行和单列的数据集。该列将是员工数量。



如果您告诉我们您要连接的数据库类型(SQL Server,Access,MySQL,SQLite等),我们可以帮助您识别连接字符串和对象以运行此查询。
You define the query, but you never run it on a database or data source. You need to run the query in order to get the data. Temp is only the SQL string, you need to make a connection to the database, then create the SQL command object, and run it. This will return a data set with a single row and a single column. That column will be the number of employees.

If you tell us what kind of database you are connecting to (SQL Server, Access, MySQL, SQLite, etc), we can help you identify the connection strings and objects to run this query.


最后解决了问题感谢Ron Beyer的宝贵意见。



Finally solved the problem Thanks to Ron Beyer for valuable idea.

<pre lang="vb">Con.CursorLocation = adUseClient
   Set cmd = New ADODB.Command
        cmd.ActiveConnection = Con

        cmd.CommandText = &amp;amp;quot;select * from employees where Designation=&amp;amp;#39;&amp;amp;quot; &amp;amp;amp; cmbodesig.Text &amp;amp;amp; &amp;amp;quot;&amp;amp;#39;&amp;amp;quot;
        cmd.CommandType = adCmdText

        Set rs = cmd.Execute
&amp;amp;#39;rs.Open &amp;amp;quot;SELECT COUNT(*) AS Posts FROM employees WHERE  designation=&amp;amp;#39;&amp;amp;quot; &amp;amp;amp; cmbodesig.Text &amp;amp;amp; &amp;amp;quot;&amp;amp;#39;&amp;amp;quot;, Con, adOpenDynamic, adLockPessimistic
   temp = rs.RecordCount
DataReport1.Sections("Section2").Controls("Label5").Caption = temp & Me.cmbodesig.Text & "@"

Thank you


这篇关于变量中查询的存储结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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