私の問題は、「シート」という名前のカスタム列を作成したことです
私のプログラムは動作しますが、コードに欠けているものがあります。それを解決する方法がわかりません。できる限りデバッグし、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