When creating a CommandBuilder a DataAdapter is passed as a parameter to the constructor. This links the CommandBuilder to a DataAdapter allowing it to read the SELECT command that has been associated with the DataAdapter. It will use the SELECT command to extract the schema information from the Table in the Database. Using this schema information it can automatically build INSERT, UPDATE and DELETE Command objects and the required SQL statements.
So, in terms of a program...
var adaptor=new OleDbDataAdapter("Select * from users", connection);
var dataSet=new DataSet();
adaptor.Fill(dataSet);
var cmdBuilder=new OleDbCommandBuilder(adaptor);
adaptor.UpdateCommand=cmdBuilder.GetUpdateCommand();
//ToDo: update dataset.
adaptor.Update(dataSet, "users");
No comments:
Post a Comment