DataAdapter.Update() does not Update the Database

后端 未结 9 2006
庸人自扰
庸人自扰 2020-12-16 16:10

I\'m sure there is an extremely simple reason that this one line isn\'t working, but it has evaded for the past week, so I\'m hoping someone else will notice my fault.

相关标签:
9条回答
  • 2020-12-16 17:11

    You might need

    DataAdapeter.AcceptChanges()
    
    0 讨论(0)
  • 2020-12-16 17:12

    Adding AcceptChangesDuringUpdate before Update works for me, example :

    foreach (string tableName in tableNames)
            {             
                da = new SqlDataAdapter("SELECT * FROM " + tableName, cn);
                cb = new SqlCommandBuilder(da); //initialise the update, insert and delete commands of da
                da.AcceptChangesDuringUpdate = true;
                da.Update(myDataSet, tableName);               
            }
    
    0 讨论(0)
  • 2020-12-16 17:15

    I have encountered the same problem. My dataadapter.fill works but dataadapter.update does not work. I realised the problem was that my database table does not contain a primary key. After I modified my table to include a column with primary key, dataadapter.fill works. Hope this helps someone.

    0 讨论(0)
提交回复
热议问题