Link to home
Start Free TrialLog in
Avatar of al4629740
al4629740Flag for United States of America

asked on

How do I update a DataGrid in VB6

I have a data grid in vb6.  I have used code to place data inthe field of my datagrid with the following code:

cboSex.text = gcol.text

However, now I want to update the field on the datagrid.  How do I update it?
Avatar of game-master
game-master
Flag of Philippines image



good morning!

datagrid is binded on the recordset. if you have a procedure that populate your
datagrid, then just call it again to update your datagrid.

game-master
Avatar of al4629740

ASKER

What do you mean by calling it again from the attached code?
Set conn = New ADODB.Connection
 
 
        If conn.State = adStateClosed Then
        conn.Open "Provider=sqloledb;Data Source=" & ConnectionIP & ",1433;Network Library=DBMSSOCN;Initial Catalog= Attendance; User ID=sa;Password=xxxxx"
        End If
        
        esql = "select * From Attendance" & DataGridProgram & " Where CommitteeName = " & ravi & DataGridOrganization & ravi
                                             
                                             
        If Combo5.text = "By Last Name" Then
        esql = esql & " order by Text1"
        End If
                        
        If Combo5.text = "By Date Enrolled" Then
        esql = esql & " order by Text20"
        End If
        
 
 
If rec.State = adStateOpen Then
        rec.Close
End If
 
      rec.CursorType = adOpenStatic
      rec.CursorLocation = adUseClient
      rec.LockType = adLockOptimistic
      rec.Open esql, conn, , , adCmdText
 
 
      
        Set DataGrid1.DataSource = rec

Open in new window



change your cursortype to adOpenDynamic...
make sure that your datagrid allowupdate property is
set to true.

question: does the database will be also updated when the cbosex is clicked or change in value? if yes, can u post your code for that update?

game-master
I think that is the exact problem.   When I select the cbosex from my dropdown, I want the database to also update.  How do I do that?

once the you have selected a value on the cbosex then moves to other
column does the value you selected appears on the cell??

if yes then just set the datagrid's alloupdate property to true. Your database
will be also updated.. Otherwise we have work to do...:-)


game-master
why should it be switched to adOpenDynamic?
ASKER CERTIFIED SOLUTION
Avatar of game-master
game-master
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial