Solved

DataGrid control not showing data (VB6.0)

Posted on 2004-04-07
9
1,192 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
Comment Utility
Set the CursorLocation to adUseClient
0
 
LVL 17

Author Comment

by:Natchiket
Comment Utility
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
Comment Utility
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
 
LVL 5

Expert Comment

by:Pi7
Comment Utility
Tell me one thing, Natchiket, does the code  MsgBox mrst.RecordCount show the expected result?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 17

Author Comment

by:Natchiket
Comment Utility
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
Comment Utility
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
Comment Utility
LockType should be adLockOptimistic
0
 
LVL 17

Author Comment

by:Natchiket
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now