首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

求救,我的DataGridView和DataAdapter如何不能更新啊

2011-12-08 
求救,我的DataGridView和DataAdapter怎么不能更新啊?已知:1、表A(ID,NAME,COMPANY),ID字段是主键,自动递增2

求救,我的DataGridView和DataAdapter怎么不能更新啊?
已知:

1、表A(ID   ,   NAME,   COMPANY),ID字段是主键,自动递增

2、代码如下:

Public   Class   frm_Main

        Dim   PListDA   As   New   OleDb.OleDbDataAdapter

        '初始化联系人列表
        Private   Sub   IniPeopleList()

                Dim   myCMD   As   New   OleDb.OleDbCommand( "Select   *   from   People ",   g_DBConnection)
                PListDA.SelectCommand   =   myCMD

                Dim   mycbd   As   New   OleDb.OleDbCommandBuilder(PListDA)

                g_DBConnection.Open()

                PListDA.Fill(DS_Main,   "PeopleList ")

                g_DBConnection.Close()

                DG_PeopleList.DataSource   =   DS_Main.Tables( "PeopleList ")

        End   Sub

        '添加联系人
        Private   Sub   TB_PeopleAdd_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   TB_PeopleAdd.Click

                Dim   NewRow   As   DataRow

                NewRow   =   DS_Main.Tables( "PeopleList ").NewRow()
                NewRow.Item( "PeopleGroupID ")   =   l_GroupID
                DS_Main.Tables( "PeopleList ").Rows.Add(NewRow)
                DS_Main.Tables( "PeopleList ").AcceptChanges()
        End   Sub

        '保存按钮
        Private   Sub   TB_PeopleSave_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   TB_PeopleSave.Click

                DS_Main.Tables( "PeopleList ").AcceptChanges()
                PListDA.Update(DS_Main.Tables( "PeopleList "))
                DS_Main.AcceptChanges()

        End   Sub

End   Class

[解决办法]
将DS_Main.Tables( "PeopleList ").AcceptChanges()去掉
另外你没有写存储过程
参考
Dim con As New OleDb.OleDbConnection( "Provider=Microsoft.Jet.OleDb.4.0;Data Source=d:\epk.mdb;Persist Security Info=True;Jet OLEDB:Database Password=fdajhi54dg4d5f54dsg ")
con.Open()
Dim rw As DataRow
dba = New OleDb.OleDbDataAdapter( "select * from dlxx ", con)
Dim upcmd As New OleDbCommandBuilder(dba)
dba.Fill(ds, "123 ")
rw = ds.Tables( "123 ").Rows(0)
rw(1) = Val(TextBox2.Text)
dba.Update(ds, "123 ")

热点排行