C#: Default.aspx.cs (Cont.)

Line 16: cmd.Parameters.AddWithValue(
    "@authorName", authorName.Text );
It adds a value to the end of the OleDbParameterCollection.

Line 17: conn.Open( );
Opens a database connection with the property settings specified by the ConnectionString.

Line 19: cmd.ExecuteNonQuery( );
Executes an SQL statement against the Connection and returns the number of rows affected.

Line 20: cmd.Dispose( );
Releases all resources used by the Component.

Line 21: conn.Close( );
Closes the connection to the data source.

Line 35: OleDbDataReader dbread = cmd.ExecuteReader( );
Sends the CommandText to the Connection, and builds an OleDbDataReader using one of the CommandBehavior values. Sends the CommandText to the Connection and builds an OleDbDataReader, which provides a way of reading a forward-only stream of data rows from a data source.

Line 36: Repeater.DataSource = dbread;
Gets or sets the data source that provides data for populating the list.

Line 37: Repeater.DataBind( );
Use the DataBind method to bind the data source specified by the DataSource property to the Repeater control. When you bind a data source to the Repeater control, the information in the data source is displayed in the control.
Default.aspx.cs
01using System;
02using System.Data.OleDb;
03 
04public partial class _Default : System.Web.UI.Page {
05 
06 protected void insert_Click( object sender, EventArgs e ) {
07  Response.Redirect( "NextPage.aspx?authorName=" +
08    authorName.Text + "&email=" + email.Text + "&type=insert" );
09 }
10 
11 protected void delete_Click( object sender, EventArgs e ) {
12  OleDbConnection conn = new OleDbConnection(
13    @"Provider=Microsoft.ACE.OleDb.12.0;Data Source=" +
14    Server.MapPath( "Access\\bookstore.mdb" ) );
15  String sql = "DELETE FROM authors WHERE authorName=@authorName";
16  OleDbCommand cmd = new OleDbCommand( sql, conn );
17  cmd.Parameters.AddWithValue( "@authorName", authorName.Text );
18  conn.Open( );
19  cmd.ExecuteNonQuery( );
20  cmd.Dispose( );
21  conn.Close( );
22  Response.Redirect( "NextPage.aspx?authorName=" +
23    authorName.Text + "&type=delete" );
24 }
25 
26 protected void search_Click( object sender, EventArgs e ) {
27  string connString = "Provider=Microsoft.ACE.OleDb.12.0;Data Source=" +
28    Server.MapPath( "Access\\bookstore.mdb" );
29  OleDbConnection conn = new OleDbConnection( connString );
30  String sql = "SELECT authorID, authorName, email FROM authors " +
31               "WHERE authorName LIKE @authorName";
32  OleDbCommand cmd = new OleDbCommand( sql, conn );
33  cmd.Parameters.AddWithValue( "@authorName", "%" + authorName.Text + "%" );
34  conn.Open( );
35  OleDbDataReader dbread = cmd.ExecuteReader( );
36  searchResult.DataSource = dbread;
37  searchResult.DataBind( );
38  dbread.Close( );
39  conn.Close( );
40  cmd.Dispose( );
41 }
42}