如何更新数据集中除一列外的所有列(CustName)

时间:2019-05-29 05:01:48

标签: vb.net

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

ID | custName | Active | Group

1  | Wanglu Lu|   1    |   1
2  | Levis Bel|   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)

1 个答案:

答案 0 :(得分: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";