Solved

DataGrid control not showing data (VB6.0)

Posted on 2004-04-07
9
1,230 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 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