Solved

DataGrid control not showing data (VB6.0)

Posted on 2004-04-07
9
1,214 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
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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Link a textbox in excel to a cell with more than 255 characters. 5 85
VBA filters 2 60
Visual Studio 2005 text editor 10 38
Export Data to Different .csv Files 26 105
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

770 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