Solved

add rows to grid depending by the number of rows returned by query.

Posted on 2007-03-26
5
203 Views
Last Modified: 2010-04-30
hoca can rows be added according to the number of rows returned by the query?

    If Not rstSelect Is Nothing Then
        If Not rstSelect.BOF And Not rstSelect.EOF Then
            Do While Not rstSelect.EOF
                 strSerialNumber = rstSelect![serial_number]
                grdSerialNumber.TextMatrix(totalRecs, 0) = strSerialNumber
                rstSelect.MoveNext
                totalRecs = totalRecs + 1
            Loop
        End If
    End If

I am getting an error for this line

grdSerialNumber.TextMatrix(totalRecs, 0) = strSerialNumber

becasue I set up the grid row property to 2 and I am getting more than that in return.
0
Comment
Question by:itortu
  • 3
  • 2
5 Comments
 
LVL 13

Accepted Solution

by:
nike_golf earned 500 total points
ID: 18795690
This might help.

    Do Until rs.EOF
        r = r + 1
        frmMain.flxResults.Rows = r + 1
        For c = 0 To rs.Fields.count - 1
            frmMain.flxResults.TextMatrix(r, c) = rs.Fields(c).Value
            ' See if we need to enlarge the column.
            new_wid = TextWidth(rs.Fields(c).Value)
            If col_wid(c) < new_wid Then col_wid(c) = new_wid
        Next c
        rs.MoveNext
    Loop

NG,
0
 

Author Comment

by:itortu
ID: 18795767
is a little bit confusing, sorry but could you explain it to me a little bit?
0
 

Author Comment

by:itortu
ID: 18795830
i changed it to this:

    If Not rstSelect Is Nothing Then
        If rstSelect.BOF And Not rstSelect.EOF Then
            Do While Not rstSelect.EOF
                r = r + 1
                grdSerialNumber.Rows = r + 1
                For c = 0 To rstSelect.Count - 1
                grdSerialNumber.TextMatrix(totalRecs, 0) = rstSelect![serial_number]
                Next c
                rstSelect.MoveNext
                totalRecs = totalRecs + 1
            Loop
        End If
    End If

but i get the error:

method or data member not found  ( rstSelect.Count )

i am on vb 6.0
0
 

Author Comment

by:itortu
ID: 18795975
ok i think i got it to work. thank you much.
please let me know if you see i can improve the way I am using your code snippet.

thank you.


    If Not rstSelect Is Nothing Then
        If Not rstSelect.BOF And Not rstSelect.EOF Then
            Do While Not rstSelect.EOF
                r = r + 1
                grdSerialNumber.Rows = r + 1
                For c = 0 To rstSelect.RecordCount - 1
                    strSerialNumber = rstSelect![serial_number]
                    grdSerialNumber.TextMatrix(totalRecs, 0) = strSerialNumber
                Next c
                rstSelect.MoveNext
                totalRecs = totalRecs + 1
            Loop
        End If
    End If
0
 
LVL 13

Expert Comment

by:nike_golf
ID: 18799615
Sorry, I just checked back in this morning. I'm glad you got it figured out.

You may not need to test for BOF unless the recordset is used in some other part of your source before you get to your loop. I think EOF would sufice, other than that it looks fine.

            Do While Not rstSelect.EOF
                r = r + 1
                grdSerialNumber.Rows = r + 1
                For c = 0 To rstSelect.RecordCount - 1
                    strSerialNumber = rstSelect![serial_number]
                    grdSerialNumber.TextMatrix(totalRecs, 0) = strSerialNumber
                Next c
                rstSelect.MoveNext
                totalRecs = totalRecs + 1
            Loop


NG,
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

706 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

18 Experts available now in Live!

Get 1:1 Help Now