0

我正在使用 VB6 从 SQL Server 导入数据并将其显示在网格中。网格有 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
4

1 回答 1

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
于 2013-06-04T12:49:00.043 回答