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( );
}
}
|