Using DataAdaptors

From PeformIQ Upgrade
Revision as of 19:01, 30 January 2011 by PeterHarding (talk | contribs) (Created page with 'http://dotnetperls.com/datagridview-tutorial See: * http://foxcentral.net/microsoft/NETforVFPDevelopers_Chapter07.htm * http://foxcentral.net/microsoft/NETforVFPDevelopers.htm ...')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

http://dotnetperls.com/datagridview-tutorial

See:

public class Supplier
{
  protected SqlDataAdapter DataAdapter;
 
  public DataSet GetSupplierByID(int supplierID)
  {
    // Build the connection string
    string ConnectionString = "server=(local);"+
       "uid=sa;pwd=;"+
       "database=Northwind";
 
    // Build the command string
    string CommandString = "SELECT supplierid, CompanyName" +
       " FROM Suppliers WHERE supplierid = " + supplierID;
 
    // Create the data adapter, passing the command and connection strings
    DataAdapter = new SqlDataAdapter(CommandString, ConnectionString);
 
    // Instantiate a DataSet object
    DataSet ds = new DataSet();
 
     // Fill the DataSet
    DataAdapter.Fill(ds);
 
    return ds;
  }
 
  /// Save the specified DataSet
  public int Save(DataSet ds)
  {
    // Create a Command Builder and build the delete, update and insert commands
    SqlCommandBuilder CommandBuilder = new SqlCommandBuilder(DataAdapter);
    DataAdapter.DeleteCommand = CommandBuilder.GetDeleteCommand();
    DataAdapter.UpdateCommand = CommandBuilder.GetUpdateCommand();
    DataAdapter.InsertCommand = CommandBuilder.GetInsertCommand();
 
    // Update the data in thet DataSet
    int RowsUpdated = DataAdapter.Update(ds, ds.Tables[0].ToString());
 
    return RowsUpdated;
  }
}