954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to geta total of a column of access in visual basic

I need to get a total of a specific column of a table of access db in a text box in my visual basic application. What should be the code? I am using adodc to connect with the database.
Help urgent please..........

shahriar2403
Light Poster
29 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

Simply try using SUM(column_name) using SQL query.

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

Would you please explain a bit more? I am not so expert in codeing. In formload i want to get it. Table name is report, Db name rate. So then......what?

shahriar2403
Light Poster
29 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

try this code. hope this will help you.........

Dim db As Database
Dim rs As Recordset
Dim tot As Double

Set db = OpenDatabase(App.Path & "\rate.mdb")
Set rs = db.OpenRecordset("report", dbOpenTable)

tot = 0

If rs.RecordCount > 0 Then
    rs.MoveFirst
    While Not rs.EOF()
        tot = tot + rs!basic_pay
        rs.MoveNext
    Wend
End If

Text1.Text = tot
choudhuryshouvi
Posting Pro
553 posts since May 2007
Reputation Points: 30
Solved Threads: 49
 

in your sql query...

SELECT SUM() as SumOfColumn from
cometburn
Junior Poster
122 posts since Feb 2008
Reputation Points: 12
Solved Threads: 19
 

many many thanks to all. thistime shuvi's code works well. thx again shuvi.

shahriar2403
Light Poster
29 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

Querying is better than looping on a recordset since this will take a certain amount of time...

Lets just say you have 100,000+ records, then you will count them 1 by 1?

cometburn
Junior Poster
122 posts since Feb 2008
Reputation Points: 12
Solved Threads: 19
 
many many thanks to all. thistime shuvi's code works well. thx again shuvi.

glad to hear that. but cometburn's syntax is also correct. you can apply that also.
(completely upto you).

ok....
if u got your answer then mark this thread solved.

regards
Shouvik

choudhuryshouvi
Posting Pro
553 posts since May 2007
Reputation Points: 30
Solved Threads: 49
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You