Using OleDbDataAdapter to update a DataTable C#

前端 未结 2 1094
傲寒
傲寒 2020-12-10 23:16

I have been trying to use OleDbDataAdapter to update a DataTable but got confused about the commands. Since I sometimes get info from diffr

2条回答
  •  温柔的废话
    2020-12-10 23:42

    You could use the String.Format Method to replace the @newVal1, @newVal2, ... in your code, like this da.UpdateCommand = new OleDbCommand(String.Format("UPDATE TABLE_NAME SET (COL1, COL2, ...) VALUES ({0}, {1}, ...) WHERE id=@id",OBJECT_ARRAY_CONTAINING_VALUES_FROM_THEDG));

    [Eidt per comment]

    To handle the row[0], row[1] you need a loop like:

    for(i=0; i

        da.UpdateCommand = new OleDbCommand(String.Format("UPDATE...",row[i]);

        da.Update(dt);

    }

提交回复
热议问题