Slide 10.11: C#: Default.aspx.cs (cont.)
Slide 10.13: C#: Default.aspx.cs (cont.)
Home

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

Line 06: protected void
The protected keyword is a member access modifier. A protected member is accessible within its class and by derived class instances. When used as the return type for a method, void specifies that the method does not return a value.

Line 06: object keyword
The object type is an alias for Object in the .NET Framework. In the unified type system of C#, all types, predefined and user-defined, reference types and value types, inherit directly or indirectly from Object. You can assign values of any type to variables of type object.

Line 06: EventArgs class
It is the base class for classes containing event data.

Line 07: Response.Redirect( URL ) method
Causes the browser to redirect the client to a different URL.

Line 12: new OleDbConnection(
Line 13:     @"Provider=Microsoft.ACE.OleDb.12.0;Data Source=" +
Line 14:     Server.MapPath("Access\\bookstore.mdb") );
It represents an open connection to a data source, where

  • Provider is to get the name of the OLE DB provider, Microsoft.ACE.OleDb.12.0 in this example, and
  • Data Source is to get the file name of the data source, where MapPath method maps the specified relative to the corresponding physical directory on the server.

Line 16: OleDbCommand cmd = new OleDbCommand( sql, conn );
It represents an SQL statement or stored procedure to execute against a data source.
Default.aspx.cs
using System;
using System.Data.OleDb;

public partial class _Default : System.Web.UI.Page {

 protected void insert_Click( object sender, EventArgs e ) {
  Response.Redirect( "NextPage.aspx?authorName=" +
    authorName.Text + "&email=" + email.Text + "&type=insert" );
 }

 protected void delete_Click( object sender, EventArgs e ) {
  OleDbConnection conn = new OleDbConnection(
    @"Provider=Microsoft.ACE.OleDb.12.0;Data Source=" +
    Server.MapPath( "Access\\bookstore.mdb" ) );
  String sql = "DELETE FROM authors WHERE authorName=@authorName";
  OleDbCommand cmd = new OleDbCommand( sql, conn );
  cmd.Parameters.AddWithValue( "@authorName", authorName.Text );
  conn.Open( );
  cmd.ExecuteNonQuery( );
  cmd.Dispose( );
  conn.Close( );
  Response.Redirect( "NextPage.aspx?authorName=" +
    authorName.Text + "&type=delete" );
 }

 protected void search_Click( object sender, EventArgs e ) {
  string connString = "Provider=Microsoft.ACE.OleDb.12.0;Data Source=" + 
    Server.MapPath( "Access\\bookstore.mdb" );
  OleDbConnection conn = new OleDbConnection( connString );
  String sql = "SELECT authorID, authorName, email FROM authors " +
               "WHERE authorName LIKE @authorName";
  OleDbCommand cmd = new OleDbCommand( sql, conn );
  cmd.Parameters.AddWithValue( "@authorName", "%" + authorName.Text + "%" );
  conn.Open( );
  OleDbDataReader dbread = cmd.ExecuteReader( );
  searchResult.DataSource = dbread;
  searchResult.DataBind( );
  dbread.Close( );
  conn.Close( );
  cmd.Dispose( );
 }
}