在VB6中重复行

时间:2013-06-04 11:57:11

标签: sql sql-server-2008 vb6

我使用VB6从SQL Server导入数据并将其显示在Grid中。网格有100行,当我尝试在网格的单行中填充数据库中的单行时,它在网格中重复100次,但我只希望它保持在一行中。我做错了什么?

代码:

While Count < 100
    Dim adoCSRS As adodb.Recordset
    Set adoCSRS = New adodb.Recordset
    adoCSRS.CursorLocation = adUseClient

    'Then comes my query which has no problem as the data is being retrieved without any problem and then'

    Dim i As Integer

    While Not adoCSRS.EOF


        'After this part, I assign the text fields their respective values from Database and then'

        i = i + 1

        MSFlexGrid.AddItem _
        adoCSRS.Fields("Coulmn Name") & Chr(9) & _
        adoCSRS.Fields("Coulmn Name") & Chr(9) & _
        adoCSRS.Fields("Coulmn Name") & Chr(9) & _
        adoCSRS.Fields("Coulmn Name") & Chr(9) & _
        adoCSRS.Fields("Coulmn Name") & Chr(9) & _
        adoCSRS.Fields("Coulmn Name") & Chr(9) & _
        adoCSRS.Fields("Coulmn Name") & Chr(9)

        MSFlexGrid.Col = 11
        MSFlexGrid.Row = i
        MSFlexGrid.CellFontName = "Wingdings"
        MSFlexGrid.CellFontSize = 10
        MSFlexGrid.CellAlignment = flexAlignCenterCenter
        MSFlexGrid.TextMatrix(i, 14) = uncheckedBox

        adoCSRS.MoveNext
    Wend

    MSFlexGrid.RowSel = 0
    successful = True

    Count = Count + 1
Wend

1 个答案:

答案 0 :(得分:0)

你需要有两个独立的(不是嵌套的)while循环。第一个循环添加数据库中的数据。第二个循环将空行添加到网格中:

Dim i As Integer
i = 0
While Not adoCSRS.EOF
  i = i + 1
  ' Add from db - same as your code above '
  MSFlexGrid.AddItem _
    adoCSRS.Fields("Coulmn Name") _
    ...
Wend

While i < 100
  i = i + 1
  ' Add blank row '
  MSFlexGrid.AddItem _
    ...
Wend