Click to See Complete Forum and Search --> : DATAGRID WITH ADO RECORDSET


HEIDI
February 28th, 2000, 12:39 PM
I am trying to bound the datagrid to the ado recordset and it will not work for me. I have tried several different ways to make this work, including examples from msdn, but I must have something wrong somewhere.

Here is the part of my code that I cannot seem to get to work:

Dim cnInjury As New ADODB.Connection
Dim Rcinjury As Recordset
Dim ssql As String
Dim ncounter As Integer
Dim oText As TextBox
On Error GoTo ErrorFormLoad

'Open the DB
cnInjury.CursorLocation = adUseClient
cnInjury.Open "ct10ms", "tgiru", "tgiru"
ssql = "select * from tgirdba.Cost_Center"
Set Rcinjury = cnInjury.Execute(ssql)

'Add fields to the text boxes in the txtCC control array
For Each oText In txtCC
Set oText.DataSource = Rcinjury
Set DataGrid1.DataSource = Rcinjury
Next


If someone could please help me out I would greatly appreciate it!!!

Heidi

d.paulson
February 28th, 2000, 08:34 PM
The data grid control is used with bound forms. Bound forms have the ado data control on them.
The data grid control is bound to the ado data control which is bound to the database.
It looks like you are using an unbound form.
You would need to use the msflexgrid control for this. Murach's Visual Basic 6 has downloadable examples of this at http://www.murach.com/books/vb60/download.htm
This has probably been one of the best books that I have purchased.

HEIDI
February 29th, 2000, 12:36 PM
I have a form with both a datagrid and a control array. Currently, The ado control recordsource is set to the db and the data grid is bound to the ado control. I can retrieve the records fine. When you double click on a record, I bring up a control array for that specific record. When I go to save it, it will update the database and show the change in the grid, but I get an error when I try to exit the program saying that the specified row could not be located for updating: Some values may have been changed since it was last read. I have tried to bookmark the record and then make the changes, but I am not having much luck. Do you have any advice on how I can update the record immediately so that I can get rid of the error?

Thanks,
Heidi

DFW
February 29th, 2000, 02:26 PM
Dim intCnt As Integer
Dim cn As Connection
Dim rs As Recordset

'Open a Connection
Set cn = New Connection
With cn
.CursorLocation = adUseClient
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\Biblio.mdb"
.Open
End With
'Open a recordset
Set rs = New Recordset
With rs
.Open "Select * from Authors", cn, adOpenDynamic
End With
'Set the Grid RecordSource
Set Grid.DataSource = rs

'Loop through the Record and Populate the Text Boxes

For intCnt = 0 To Text1.UBound
Text1(intCnt).Text = "" & rs.Fields(intCnt)
Next