DataAdapter.Update() does not Update the Database

后端 未结 9 2036
庸人自扰
庸人自扰 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:09

    In order to update the data on the database your SqlDataAdapter need to have its InsertCommand, UpdateCommand, DeleteCommand properties set. The SqlCommandBuilder instance that you've created has these commands but you need to set them to your SqlDataAdapter.

    In other worlds: Somewhere between

     SqlCommandBuilder cb;
     cb = new SqlCommandBuilder(dataAdapt);
    

    and

     dataAdapt.Update(dataRecipe, "CookBookRecipes");
    

    you need to

    dataAdapt.DeleteCommand = cb.GetDeleteCommand(true);
    dataAdapt.UpdateCommand = cb.GetUpdateCommand(true);
    dataAdapt.InsertCommand = cb.GetInsertCommand(true);
    

提交回复
热议问题