DataGridView选择插入新列不更新现有列

时间:2016-04-05 13:50:24

标签: vb.net datagridview

我创建了一个使用SQLAdapter获取其数据的DataGridView。

我已经预先添加了列,因为我需要2个文本列,然后是几个复选框列。

从SQL适配器返回的值为0/1,表示复选框的布尔值。

但是,当选择数据而不是更新现有列时,它会再次将所有数据添加为附加列。

为什么它的表现如此?

我的代码

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    oCon = New SqlConnection
    oCon.ConnectionString = "Data Source=*********;Initial Catalog=******;Persist Security Info=True;User ID=*****;Password=*****"
    dsUsers = New DataSet
    daUsersList = New SqlDataAdapter("SELECT ID , Username ,Active, Autosaint , Ladybird , Home , [Motor Trade] , First , Audit , Finance  FROM *******.dbo.******", oCon)
    '*** Define command builder to generate the necessary SQL
    Dim builder As SqlCommandBuilder = New SqlCommandBuilder(daUsersList)
    builder.QuotePrefix = "["
    builder.QuoteSuffix = "]"

    Try
        daUsersList.FillSchema(dsUsers, SchemaType.Source, "UserList")
        daUsersList.Fill(dsUsers, "UserList")
        tblUsers = dsUsers.Tables("UserList")
        DGVUsers.DataSource = tblUsers

    Catch ex As Exception
        MsgBox("Something has gone wrong..." & vbNewLine & ex.Message)

    End Try

End Sub

截图

http://postimg.org/image/u6z1u5h5h/

干杯。

0 个答案:

没有答案