C # is a language that is fully object-to-object, accessing the database is also completed by several classes in the .NET class library. Side main introduction
Several OLEDBCONNECTION, OLEDBCOMMAND, OLEDBDATAADAPTER, DATASET, DATATABLE
1. OLEDBConnection It encapsulates the database connection, initializes it through the Connectionstring property.
Example: OLEDBConnection conn = new oledbconnection ();
Conn.connectionstring = "provider = msdaora.1; data source = datasource; user id = user; password = pass";
2. OLDBCommand This encapsulates the SQL statement that can be executed, such as select, update, insert, delete, etc., you can use the OLEDBConnection, SQL statements to initialize;
Example: OLEDBCommand cmd = new oledbcommand ();
CMD.Connection = conn; // The connection object above
cmd.comMandtext = "Select * from sometable";
Note: The initialization method mentioned above is not unique. The other is the same below, and the specific can be referred to MSDN.
Www.microsoft.com/china/msdn
3. OLDBDataAdapter It is a link between DataSet and physical databases, which is responsible for populating data in the physical database into the DataSet for editing or display, and can also update data in the DataSet to the physical database;
Example: OLEDBDataAdapter mydataadapter = new oledbdataadapter ();
MyDataAdapter.connection = conn;
MyDataAdapter.selectCommand = CMD;
DataSet DataSet = New Dataset (); // Defines a data set, actually a buffer of memory
MyDataAdapter.Fill (DataSet); // Add data from the physical database to the data set
// .....
// Here you can handle the data set
// .....
MyDataAdapter.Update (Dataset); // Update data in the data to the physical database
MyDataAdapter.Update (DataSet.getChanges ()) // Promote some data changed in the data to the database
These all can be automatically generated with .NET2003's wizard, of course, you can also write these code yourself.
A DataSet consists of several DataTable, a DataTable consists of several DATAROW and several Datacolumn.
There is also a DataView, which corresponds to a single DataTable, which generally uses it as a data source for the WinForm window control, because modifying its RowFilter property to achieve flexible dynamic filtering.