This is no longer something new. It is still one of the very handy ways to update the data in SQL database, despite it is SyBase, MS SQl or Oracle.
You need no to implicitly specify InsertCommand, UpdateCommand, or DeleteCommand at design time or run time. You do need to specify the SelectCommand for instance “SELECT * FROM dbo.Products” when using DbCommandBuilder.
The code snippet below retrieves all the rows from SunMoon database and update the 4th column of the first record.
// Assumes that connection is a valid SqlConnection object
// inside of a using block.
string connection = @”Data Source=.\SQLEXPRESS;Initial Catalog=SunMoon;Integrated Security=True”;
SqlDataAdapter adapter = newSqlDataAdapter(
“SELECT * FROM dbo.Products”, connection);
SqlCommandBuilder builder = newSqlCommandBuilder(adapter);
DataSet ds = newDataSet();
builder.QuotePrefix = “[";
builder.QuoteSuffix = "]“;
ds.Tables.Rows = “Piano”;
Note: Without the lineSqlCommandBuilder builder = newSqlCommandBuilder(adapter); in C# andDim builder AsNewSqlCommandBuilder(adapter) in VB the code will run but the record will not be updated.