hello...im new in vb world.so please help me if someone can..my problem in details:
1.have created a ms access database file named Database2.mdb which has 5 columns as follows a,b,c,d and result.it has 5 row and a,b,c,d are filled with data but result column is empty.
2.have created a datagrid in vb6 and connected this database file with datagrid and it is showing well..no problem..
3.now wrote a code in another form as

For rowcount = 1 To Adodc1.Recordset.RecordCount
a = DataGrid1.Columns(1).Text
b = DataGrid1.Columns(2).Text
c = DataGrid1.Columns(3).Text
d = DataGrid1.Columns(4).Text

result=a+b+c+d

(here should be some step to update the value of result in each iteration in that datagrid result column..)
next
problem:could not update the databse with those calculated result...please help someone..

U may use the following line

ADODC1.RECORDSET!RESULT=a+b+c+d where adodc1 is the ado datacontrol to which grid1 is bound


Bashir

u can also use sql statement:

adodc1.recordsource="select a,b,c,d,(a+b+c+d) as [Result] from table1
adodc1.refresh
set datagrid1.datasource=adodc1

in this way the grid will be populated with the records u want.

thx.

hello...im new in vb world.so please help me if someone can..my problem in details:
1.have created a ms access database file named Database2.mdb which has 5 columns as follows a,b,c,d and result.it has 5 row and a,b,c,d are filled with data but result column is empty.
2.have created a datagrid in vb6 and connected this database file with datagrid and it is showing well..no problem..
3.now wrote a code in another form as

For rowcount = 1 To Adodc1.Recordset.RecordCount
a = DataGrid1.Columns(1).Text
b = DataGrid1.Columns(2).Text
c = DataGrid1.Columns(3).Text
d = DataGrid1.Columns(4).Text

result=a+b+c+d

(here should be some step to update the value of result in each iteration in that datagrid result column..)
next
problem:could not update the databse with those calculated result...please help someone..

Hi,

You can use the below code, it may help you.

Private Sub Command1_Click()
Adodc1.Recordset.MoveFirst 'Move the record position to the first
'Iteration for row by row update

For i = 1 To Adodc1.Recordset.RecordCount

    'Calculate the result
    a = Val(DataGrid1.Columns(0).Text) + Val(DataGrid1.Columns(1).Text)+                Val(DataGrid1.Columns(2).Text)+ Val(DataGrid1.Columns(3).Text)

    'Assign the result to the field
    Adodc1.Recordset.Fields("result") = a 

    'Update the recordset
    Adodc1.Recordset.Update 

    'Move to the Next recordset
    Adodc1.Recordset.MoveNext 
Next
End Sub

Shailaja :)

This article has been dead for over six months. Start a new discussion instead.