Solved

DataGrid control not showing data (VB6.0)

Posted on 2004-04-07
9
1,238 Views
Last Modified: 2007-12-19
Hi,

This is probably a very easy question but it's driving me nuts!

I'm using a datagrid control, and i'm trying to populate it directly from an ADO recordset.  (i.e NOT using an ADO data control)
However, when my code runs allthough rows apear in the grid, indicating where the records should be, no data is displayed in the cells.

Code as below...

strSQL = "SELECT ViewFieldName,FieldName FROM tQueryFields WHERE QueryID=" & mlngQID
        Set mrst = New ADODB.Recordset
        mrst.Open Source:=strSQL, ActiveConnection:=cnn, CursorType:=adOpenKeyset
        MsgBox mrst.RecordCount
       
        Set Me.dgFields.DataSource = mrst
       
        intField = 0
        For Each fld In mrst.Fields
            With dgFields.Columns(intField)
                .Visible = True
                .Caption = fld.Name
                .DataField = fld.Name
                .Width = 2000
            End With
            intField = intField + 1
        Next
           
        dgFields.Refresh

Can anyone help ?

Regards, nat.

0
Comment
Question by:Natchiket
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 28

Assisted Solution

by:vinnyd79
vinnyd79 earned 50 total points
ID: 10774817
Set the CursorLocation to adUseClient
0
 
LVL 17

Author Comment

by:Natchiket
ID: 10774925
Thanks, I've tried that but it didn't make any difference...

strSQL = "SELECT ViewFieldName 'Source Name',FieldName 'Fiendly Name' FROM tQueryFields WHERE QueryID=" & mlngQID
        Set mrst = New ADODB.Recordset
        mrst.CursorLocation = adUseClient
        mrst.Open Source:=strSQL, ActiveConnection:=cnn, CursorType:=adOpenKeyset
     
       
        Set Me.dgFields.DataSource = mrst
       
        intField = 0
        For Each fld In mrst.Fields
            With dgFields.Columns(intField)
                .Visible = True
                .Caption = fld.Name
                .DataField = fld.Name
                .Width = 2000
            End With
            intField = intField + 1
        Next
           
        dgFields.Refresh
0
 
LVL 17

Author Comment

by:Natchiket
ID: 10775258
Ok I've fixed that by deleteing the old data control and putting in a new one.

The problem is now that when I try and overtype data it won't let me change it (allowUpdate is ticked in the control properties)

 strSQL = "SELECT ViewFieldName 'Source Name',FieldName 'Fiendly Name' FROM tQueryFields WHERE QueryID=" & mlngQID
        Set mrst = New ADODB.Recordset
        mrst.CursorLocation = adUseClient
        mrst.Open Source:=strSQL, ActiveConnection:=cnn, CursorType:=adOpenDynamic
     
       
        Set Me.dgFields.DataSource = mrst
       
       
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 5

Expert Comment

by:Pi7
ID: 10776365
Tell me one thing, Natchiket, does the code  MsgBox mrst.RecordCount show the expected result?
0
 
LVL 17

Author Comment

by:Natchiket
ID: 10781565
Yes msgbox mrst.recordcount is fine thanks
As in my comment 04/07/2004 07:40AM PDT, it's now showing the data.  but for some reason won't let it be edited.


0
 
LVL 5

Expert Comment

by:Pi7
ID: 10782360
Well I'm not sure why you're experiencing this.Try the changes below
Change cursor type to adOpenDynamic and
set LockType to adLockOptimist

These are the settings I always use and they always work for me
Regards,
Pi7
0
 
LVL 5

Accepted Solution

by:
Pi7 earned 200 total points
ID: 10782414
LockType should be adLockOptimistic
0
 
LVL 17

Author Comment

by:Natchiket
ID: 10782457
Well I've gone for a list box/text box solution as I've run out of time/patience with the datagrid control
Why is the VB listbox so crummy ? The Access listbox is so much more powerful
Anyway enough griping
In view of everyone's efforts I shall split points 200 pi7 and 50 vinnyd79
Hope everyone thinks this is fair
0
 

Expert Comment

by:ramyah
ID: 10984590
It may due to the error in our database,no error in ur coding.i run ur code with my own database and data is viewed in the grid.chk ur table.
by
ram
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question