Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

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

I searched a lot on the web but no results
Please help me
Thank you
Sarfaraz
Posted
Updated 21-Jun-13 21:24pm
v3

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.
 
Share this answer
 
Comments
sarfarazbhat 22-Jun-13 3:21am    
I am using Access database with ado.
i was using like

temp = "select count(*) from employees where designation='" & cmbodesig.Text & "'", Con, adOpenDynamic, adLockPessimistic
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
 
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