using System;
using System.Data.OleDb;
public partial class NextPage : System.Web.UI.Page {
protected void Page_Load( object sender, EventArgs e ) {
if ( Request.QueryString["type"] == "delete" ) {
Result.Text = "The author, " +
Request.QueryString["authorName"] + ", is deleted.";
}
else {
Result.Text = "The author, " +
Request.QueryString["authorName"] + ", is inserted.";
if ( !Page.IsPostBack ) {
OleDbConnection conn = new OleDbConnection(
@"Provider=Microsoft.ACE.OleDb.12.0;Data Source=" +
Server.MapPath( "Access\\bookstore.mdb" ) );
String sql = "INSERT INTO authors( authorName, email )";
sql += "VALUES( @authorName, @email )";
OleDbCommand cmd = new OleDbCommand(sql, conn);
cmd.Parameters.AddWithValue( "@authorName", Request.QueryString["authorName"] );
cmd.Parameters.AddWithValue( "@email", Request.QueryString["email"] );
conn.Open( );
cmd.ExecuteNonQuery( );
cmd.Dispose( );
conn.Close( );
}
}
}
protected void home_Click( object sender, EventArgs e ) {
Response.Redirect( "Default.aspx" );
}
protected void authorList_SelectedIndexChanged( object sender, EventArgs e ) {
OleDbConnection conn = new OleDbConnection(
@"Provider=Microsoft.ACE.OleDb.12.0;Data Source=" +
Server.MapPath( "Access\\bookstore.mdb" ) );
String sql = "SELECT authorID, authorName, email ";
sql += "FROM authors WHERE authorName = @authorName";
OleDbCommand cmd = new OleDbCommand( sql, conn );
cmd.Parameters.AddWithValue( "@authorName", authorList.SelectedValue );
conn.Open( );
var dbread = cmd.ExecuteReader( );
author.DataSource = dbread;
author.DataBind( );
dbread.Close( );
conn.Close( );
}
}
|