?
Solved

DataGrid control not showing data (VB6.0)

Posted on 2004-04-07
9
Medium Priority
?
1,240 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 200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 800 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

764 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