如何隐藏其他列

how to hide other column

在我的数据网格视图中,我只想显示其他字段,例如 ID、姓氏、名字和中间名,我不想显示任何字段,但我希望它即使被隐藏也能检索。但是当我指定我只想在我的 datagridview 中显示的内容时,它会导致运行时错误。

这是我加载数据网格视图的代码。

MysqlConn.Open()
        Dim Query As String
        Query = "select ID,LastName,FirstName,MiddleName from god.precord"

        COMMAND = New MySqlCommand(Query, MysqlConn)
        SDA.SelectCommand = COMMAND
        SDA.Fill(dbDataSet)
        bSource.DataSource = dbDataSet
        DataGridView1.DataSource = bSource
        SDA.Update(dbDataSet)

        MysqlConn.Close()


    Catch ex As Exception
        MessageBox.Show(ex.Message)
    Finally
        MysqlConn.Dispose()

    End Try

那么这是我将数据检索到文本框中的代码

    Private Sub DataGridView1_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick



    If e.RowIndex >= 0 Then
        Dim row As DataGridViewRow
        row = Me.DataGridView1.Rows(e.RowIndex)
        txtid.Text = row.Cells("ID").Value.ToString
        txtlastname.Text = row.Cells("LastName").Value.ToString
        txtfirstname.Text = row.Cells("FirstName").Value.ToString
        txtmiddlename.Text = row.Cells("MiddleName").Value.ToString
        txtaddress.Text = row.Cells("Address").Value.ToString
        txtcontactno.Text = row.Cells("ContactNo").Value.ToString
        txtgender.Text = row.Cells("Gender").Value.ToString
        dtpbirthdate.Text = row.Cells("Birthdate").Value.ToString
        txtage.Text = row.Cells("Age").Value.ToString

    End If

End Sub

runtime error

请帮助我这是我的论文 提前谢谢你 <3

您必须将隐藏列添加到 select 查询中才能检索数据。

改为隐藏 DataGridView 中的列。

try
    MysqlConn.Open()
    Dim Query As String
    Query = "select ID,LastName,FirstName,MiddleName,Address from god.precord"

    COMMAND = New MySqlCommand(Query, MysqlConn)
    SDA.SelectCommand = COMMAND
    SDA.Fill(dbDataSet)
    bSource.DataSource = dbDataSet
    DataGridView1.DataSource = bSource
    SDA.Update(dbDataSet)
    DataGridView1.Columns("Address").Visible = false

    MysqlConn.Close()


Catch ex As Exception
    MessageBox.Show(ex.Message)
Finally
    MysqlConn.Dispose()

End Try