Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > Populating a Datagrid in VB6


Reply
 
Thread Tools Display Modes
  #1  
Old 04-27-2006, 06:00 AM
Winnie Winnie is offline
Newcomer
 
Join Date: Apr 2006
Posts: 6
Default Populating a Datagrid in VB6


I'm having real trouble populating a datagrid from a recordset in vb6.

Here's my code.

Code:
Private Sub cmdSearch_Click()
    Dim sConn As String 'for the connection string
    
    Dim db As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim sPath As String
    Dim sSQL As String
    Dim SubID As String
    
    sPath = App.Path & "\SSADM.mdb;"
    sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sPath
    db.ConnectionString = sConn
    db.Open
    SubID = txtSubsID.Text
    sSQL = " Select * From Subscriber WHERE SubscriberID =" & SubID & ""
    
    With rs
        .ActiveConnection = db
        .LockType = adLockOptimistic
        .CursorType = adOpenKeyset
        .Open sSQL

        lblName.Caption = .Fields("SubName").Value
        
        
    End With
    
    Set dgCurrentSubs.DataSource = Nothing
    Set dgCurrentSubs.DataSource = rs
    dgCurrentSubs.Refresh
    lblName.Visible = True
    
    Set rs = Nothing
    db.Close
    Set db = Nothing
    
End Sub
The connection obviously works as the label displays the field fine. Do I need to do anything to the datagrid itself? Currently, nothing loads into the grid. Even if I move the 'SET dgCurrentSubs' statements into the WITH it doesn't work.
Reply With Quote
  #2  
Old 04-27-2006, 06:06 AM
George7a's Avatar
George7a George7a is offline
Saved by Grace
 
Join Date: Mar 2005
Location: Nazareth
Posts: 1,697
Default

Hi,

Check the following links:
Good Tutorial
http://www.planetsourcecode.com/vb/s...59923&lngWId=1


I hope it helps,

- George

Last edited by George7a; 04-27-2006 at 06:12 AM.
Reply With Quote
  #3  
Old 04-27-2006, 06:51 AM
Winnie Winnie is offline
Newcomer
 
Join Date: Apr 2006
Posts: 6
Default

Great, Cheers, got it working now.

Quick question, If I have the row index of a row in the datagrid, how do I obtain a values from one of the columns on that row? If my column name is "PubID"?

I'll search the forum now to see if its on here already.
Reply With Quote
  #4  
Old 04-27-2006, 06:55 AM
Winnie Winnie is offline
Newcomer
 
Join Date: Apr 2006
Posts: 6
Default

Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->