7 Replies - 932 Views - Last Post: 14 January 2013 - 06:18 PM Rate Topic: -----

#1 anandrosan1  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 23
  • Joined: 20-December 12

VB6 DATAGRID Error

Posted 12 January 2013 - 08:30 PM

Hi all ! I am using vb6 and Datagrid ! I have an access database and i display those records in datagrid ! For example, there is a column named marks ! Below the datagrid there is a button and textbox named total ! if i click the button means, then the marks column in the datagrid should be added and display the result in the textbox ! I have tried the following method but it doesn't work !
Public con As New ADODB.Connection
Public rs As New ADODB.Recordset

In the form load the following code contains !

Set con = New ADODB.Connection
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\college.mdb;Persist Security Info=False"
con.CursorLocation = adUseClient
Set rs = New ADODB.Recordset
rs.open "select marks from student",con,1,3
set Datagrid1.Datasource = rs


The marks column in the access is displaying correctly in the datagrid ! but i don't know how to take the values from the datagrid and add them up and display the total marks in a textbox ! Thanks in advance !

Is This A Good Question/Topic? 0
  • +

Replies To: VB6 DATAGRID Error

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3371
  • View blog
  • Posts: 11,420
  • Joined: 12-December 12

Re: VB6 DATAGRID Error

Posted 12 January 2013 - 08:57 PM

You would loop through the underlying recordset:

Dim dblSum As Double
  
rs.MoveFirst
Do While Not rs.EOF
    dblSum = dblSum + rs.Fields(2)    'or .Fields("marks") or .Fields!marks
    rs.MoveNext
Loop
TextBox1.Text = "Total: " & dblSum
  
rs.MoveFirst


BTW I'm unable to test this as I don't have VB6.

This post has been edited by andrewsw: 12 January 2013 - 08:59 PM

Was This Post Helpful? 1
  • +
  • -

#3 anandrosan1  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 23
  • Joined: 20-December 12

Re: VB6 DATAGRID Error

Posted 12 January 2013 - 11:00 PM

It works friend ! thanks !
Was This Post Helpful? 0
  • +
  • -

#4 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,772
  • Joined: 26-March 09

Re: VB6 DATAGRID Error

Posted 13 January 2013 - 02:41 AM

Or alternatively, you could use a query similar to what you had...

something like...

Select sum(marks) from student

Was This Post Helpful? 1
  • +
  • -

#5 anandrosan1  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 23
  • Joined: 20-December 12

Re: VB6 DATAGRID Error

Posted 13 January 2013 - 10:17 AM

This problem has been solved ! Here is another problem and take a look here http://goo.gl/fmXvs
Was This Post Helpful? 0
  • +
  • -

#6 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,772
  • Joined: 26-March 09

Re: VB6 DATAGRID Error

Posted 13 January 2013 - 11:03 AM

View Postanandrosan1, on 13 January 2013 - 05:17 PM, said:

This problem has been solved ! Here is another problem and take a look here http://goo.gl/fmXvs

Yes, I realised it was solved, I was just giving you an alternative for future.
Was This Post Helpful? 1
  • +
  • -

#7 anandrosan1  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 23
  • Joined: 20-December 12

Re: VB6 DATAGRID Error

Posted 13 January 2013 - 07:56 PM

Yes i know friend thank you so much ! did you take a look into the new link that I've given above and could you give me an idea in that friend?
Was This Post Helpful? 0
  • +
  • -

#8 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: VB6 DATAGRID Error

Posted 14 January 2013 - 06:18 PM

As I mentioned in another post, please stop using exclamation points in your writing until you learn how to use them properly. It's very distracting and makes it hard to understand what you are saying. Thank you!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1