






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This programming course teaches different programming concepts with respect to C Sharp Programming. Key points of this lecture are: Ado.Net Framework, Dataadapters, Datasets and Datatables, Providers, Type of Database, Connectionstring, Sqlconnection, Oledbconnection, Oledbcommands, Using a Connection
Typology: Slides
1 / 30
This page cannot be seen from the preview
Don't miss anything!























Creating connections to providing Executing SQL commands using providers that Return nothing Return one value Read data one record at a time Use DataAdapters to create in-memory datasets and datatables
The OleDbConnection and SQLConnection classes give us the means to make a database connection Commands are sent over this connection The ConnectionString property contains the string that the systems uses to make the database connection It differs from provider to provider
Call the Open and Close methods to explicitly open and close the connections Use for OleDbCommands Some objects call these methods for you
Once we have created a connection, we send commands over that connection Most commonly using the OleDbCommand or SqlCommand objects There are properties to configure the command and connection There are methods to execute the command using the connection
CommandText property stores SQL statement that will be executed against a provider Connection property stores a reference to existing OleDbConnection object
Parameters property stores a reference to a Parameters collection (more later)
The ExecuteScalar method returns a single value (first column / first row) Will not fail if you return multiple rows Use to get a max ID value
It’s a forward-only reader (like a stream) You read one record at a time Each time a record is read, the reader contains a reference to an array of fields
Place an SQL SELECT statement in the OleDbcommand Call ExecuteReader to create the forward- only reader Call Read to read each record Then call the various Get methods to get the value of each field
This gets a bit more complicated We need another object called a DataAdapter Microsoft calls it a bridge between a DataSet and a DataSource Again, there are OleDb and Sql Server versions of these
I’ll go through the OleDbDataAdapter and DataSet , in turn
OleDbDataAdapter works in conjunction with the DataSet class to read and write data Commands are sent over a connection Data is retrieved into a DataSet Commands to insert, update, or delete data return nothing
Fill method uses an OleDbConnection to retrieve database records Records are loaded into a DataSet Update method examines the DataSet for any added, changed, or deleted records Changes are recorded to DataSet Call AcceptChanges method on DataSet to synchronize DataSet and database
FillError event fires if an error occurs while populating the DataSet RowUpdating event fires just before row is updated RowUpdated event fires just after a row in the data source is updated