02 | using System.Data.OleDb; |
04 | public partial class NextPage : System.Web.UI.Page { |
06 | protected void Page_Load( object sender, EventArgs e ) { |
07 | if ( Request.QueryString[ "type" ] == "delete" ) { |
08 | Result.Text = "The author, " + |
09 | Request.QueryString[ "authorName" ] + ", is deleted." ; |
12 | Result.Text = "The author, " + |
13 | Request.QueryString[ "authorName" ] + ", is inserted." ; |
14 | if ( !Page.IsPostBack ) { |
15 | OleDbConnection conn = new OleDbConnection( |
16 | @"Provider=Microsoft.ACE.OleDb.12.0;Data Source=" + |
17 | Server.MapPath( "Access\\bookstore.mdb" ) ); |
18 | String sql = "INSERT INTO authors( authorName, email )" ; |
19 | sql += "VALUES( @authorName, @email )" ; |
20 | OleDbCommand cmd = new OleDbCommand(sql, conn); |
21 | cmd.Parameters.AddWithValue( "@authorName" , Request.QueryString[ "authorName" ] ); |
22 | cmd.Parameters.AddWithValue( "@email" , Request.QueryString[ "email" ] ); |
24 | cmd.ExecuteNonQuery( ); |
31 | protected void home_Click( object sender, EventArgs e ) { |
32 | Response.Redirect( "Default.aspx" ); |
35 | protected void authorList_SelectedIndexChanged( object sender, EventArgs e ) { |
36 | OleDbConnection conn = new OleDbConnection( |
37 | @"Provider=Microsoft.ACE.OleDb.12.0;Data Source=" + |
38 | Server.MapPath( "Access\\bookstore.mdb" ) ); |
39 | String sql = "SELECT authorID, authorName, email " ; |
40 | sql += "FROM authors WHERE authorName = @authorName" ; |
41 | OleDbCommand cmd = new OleDbCommand( sql, conn ); |
42 | cmd.Parameters.AddWithValue( "@authorName" , authorList.SelectedValue ); |
44 | var dbread = cmd.ExecuteReader( ); |
45 | author.DataSource = dbread; |
|