RefreshSchema
CommandBuilder.RefreshSchema();
Refreshes the schema that automatically generates the
DeleteCommand
, InsertCommand
,
and UpdateCommand
.
The following example demonstrates how to use the
RefreshSchema( )
method:
// connection and select command strings String connString = "Data Source=(local);Integrated security=SSPI;" + "Initial Catalog=Northwind;"; SqlConnection conn = new SqlConnection(connString); String sqlSelect = "SELECT * FROM Orders"; SqlCommand selectCommand = new SqlCommand(sqlSelect, conn); SqlDataAdapter da = new SqlDataAdapter(selectCommand); // create the command builder SqlCommandBuilder cb = new SqlCommandBuilder(da); // retrieve the DeleteCommand SqlCommand deleteCommand = cb.GetDeleteCommand(); // change the select statement sqlSelect = "SELECT OrderID, CustomerID, EmployeeID FROM Orders"; selectCommand = new SqlCommand(sqlSelect, conn); // have to call RefreshSchema before retrieving the DeleteCommand again cb.RefreshSchema(); deleteCommand = cb.GetDeleteCommand();
The RefreshSchema( )
method should be called
whenever the SELECT statement associated with the
CommandBuilder
changes.
The RefreshSchema( )
method
doesn’t cause the updating logic in the
DeleteCommand
, InsertCommand
,
and UpdateCommand
objects to be regenerated
immediately. The updating logic is regenerated when the
DataAdapter
Update( )
method is
called or when the GetDeleteCommand( )
,
GetInsertCommand( )
, or GetUpdateCommand( )
method is
called.