CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2000
    Location
    NC, USA
    Posts
    56

    DATAGRID WITH ADO RECORDSET

    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


  2. #2
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: DATAGRID WITH ADO RECORDSET

    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.


  3. #3
    Join Date
    Jan 2000
    Location
    NC, USA
    Posts
    56

    Re: DATAGRID WITH ADO RECORDSET

    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


  4. #4
    Join Date
    Feb 2000
    Posts
    11

    Re: DATAGRID WITH ADO RECORDSET

    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




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured