1

我的问题是,我创建了一个自定义列,我将其命名为“座位”

我的程序可以工作,但是代码中缺少一些东西,我不知道如何解决它,我尽我所能调试,我使用 msgboxes 只是为了显示 countVal 值,它在 MsgBox 中可以工作,但是他们的我的这行代码有问题吗

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

那行代码只显示一次输出,但如果我再次单击按钮以显示带有 DataGridView 的表单,唯一会显示的是我的表中的“SELECT statements”列,而自定义列“Available”座位”是空的。

我已经尝试过使用,刷新,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

我的猜测是你打算用 i 变量而不是 startVal 循环遍历行,因为你的代码总是更新同一行:

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

try add this code

dgsection.rows.add before this dgSection.Rows.Item(startVal).Cells("seat").Value = countVal 'there is something wrong about this line and change the

dgsection.rows.item(startval)

to

dgsection.rows.item(i)

then tell me what happen.. or can you can printscreen

also i need to know, what is the problem show of the line?

于 2013-03-13T03:01:47.287 回答
0

利用

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