1

私の問題は、「シート」という名前のカスタム列を作成したことです

私のプログラムは動作しますが、コードに欠けているものがあります。それを解決する方法がわかりません。できる限りデバッグし、countVal 値を表示するためだけに msgboxes を使用しました。MsgBox に関しては動作しますが、私のコードのこの行に何か問題がありますか

dgSection.Rows.Item(startVal).Cells("seat").Value = countVal

そのコード行は出力を 1 回だけ表示しますが、ボタンをもう一度クリックして DataGridView でフォームを表示すると、表示されるのはテーブルの「SELECT ステートメント」列だけで、カスタム列は「使用可能」です。シート」は空です。

私はすでに更新、Datasource = Nothing、rows.clear() を使用しようとしましたが、それらはまったく効果がありません。

この問題について助けていただけませんか?


    If dgSection.Columns.Contains("seat") = True Then
        dgSection.Columns.Remove("seat")
    End If

    FillGrid("SELECT SID,year_level,EntryID,Section,Year,MaxNumber FROM tbl_section LEFT JOIN tbl_personal_data ON tbl_section.Year = tbl_personal_data.year_level WHERE SID = " & frm_Enroll.SID, "tbl_section", dgSection)
    dgSection.Columns(0).Visible = False
    dgSection.Columns(1).Visible = False

    dgSection.Columns.Add("seat", "Available Seat")

    Dim i As Integer = 0
    Dim startVal As Integer = 0

    For i = startVal To dgSection.Rows.Count - 1
        Try
            DS = New DataSet
            DS.Clear()
            Comm = CONN.CreateCommand
            Comm.CommandText = "SELECT * FROM tbl_personal_data WHERE section_id = " & dgSection.Rows(i).Cells(2).Value
            DA.SelectCommand = Comm
            DA.Fill(DS, "tbl_personal_data")
            CONN.Close()

            Dim countVal As Integer
            For Each table As DataTable In DS.Tables
                countVal = countVal + table.Rows.Count
            Next

            MsgBox(countVal) 'this is working it shows the counted rows

            dgSection.Rows.Item(startVal).Cells("seat").Value = countVal 'there is something wrong about this line
        Catch ex As Exception
            MsgBox("Error number:" & Err.Number & vbCrLf & ex.Message, MsgBoxStyle.Critical)
        Finally
            CONN.Close()
        End Try
    Next i
4

3 に答える 3

0

コードは常に同じ行を更新しているため、startValではなくi変数を使用して行をループすることを意図していると思います。

'dgSection.Rows.Item(startVal).Cells("seat").Value = countVal
dgSection.Rows.Item(i).Cells("seat").Value = countVal
于 2012-12-18T21:00:28.000 に答える
0

使用する

dgSection.Rows(startVal).Cells("seat").Value = countVal
于 2015-02-18T11:36:44.007 に答える
0

このコードを追加してみてください

dgsection.rows.add この前 dgSection.Rows.Item(startVal).Cells("seat").Value = countVal 'there is something wrong about this line

dgsection.rows.item(startval)

dgsection.rows.item(i)

それから何が起こるか教えてください..またはプリントスクリーンできますか

また、私は知る必要があります。ラインの問題は何ですか?

于 2013-03-13T03:01:47.287 に答える