0

我正在处理帐户权限管理,但我需要从 datagridview 输入更新 sql 数据库中表中的所有列,但一个特定列除外。谢谢!

身份证 | 客户名 | 活跃 | 团体

1 | 望路路| 1 | 1
2 | 李维斯贝尔| 0 | 2
Dim comm As New SqlCommand
Dim dbread As SqlDataReader
Dim adptr As New SqlDataAdapter
Dim dt As New DataTable
Dim ds As New DataSet
Dim myBuilder As SqlCommandBuilder

Private Sub lbldgvUserID_TextChanged(sender As Object, e As EventArgs) Handles lbldgvUserID.TextChanged
    Try
        conn.Open()
        With comm
            .Connection = conn
            .CommandText = "SELECT ID,custName,Active,Group FROM tbl_customer WHERE ID= '" + lblUserID.Text + "'"
        End With
        adptr.SelectCommand = comm
        'dt.Clear()
        ds.Clear()
        adptr.Fill(ds, "tbl_customer")
        dgvPermissions.DataSource = ds.Tables("tbl_custorer").Rows(0)
    Catch ex As Exception
        MsgBox(ex.Message)
        conn.Close()
        End With
    End Try


    Dim builder As SqlCommandBuilder = New SqlCommandBuilder(adptr)

    adptr.Update(ds, "tbl_customer")
    MsgBox("Customer info successfuly updated!", MsgBoxStyle.Information)
4

1 回答 1

0

您可以在数据集中获取结果后更新列名。这是一个片段。

        DataTable table = new DataTable();
        table.Columns.Add("Dosage", typeof(int));
        table.Columns.Add("Drug", typeof(string));
        table.Rows.Add(25, "Indocin");
        table.Columns["Dosage"].ColumnName = "Dosage1";
于 2019-05-29T05:28:24.680 回答