using System;
using System.Data.OleDb;
namespace WebApplication3 {
public partial class WebForm1 : System.Web.UI.Page {
protected void Add_Click( object sender, EventArgs e ) {
OleDbConnection conn = new OleDbConnection(
@"Provider=Microsoft.ACE.OleDb.12.0;Data Source=" +
Server.MapPath( "Access\\enrollment.mdb" ) );
String sql = "INSERT INTO courses( title ) VALUES ( @title )";
OleDbCommand cmd = new OleDbCommand( sql, conn );
cmd.Parameters.AddWithValue( "@title", title.Text );
conn.Open( );
cmd.ExecuteNonQuery( );
cmd.Dispose( );
conn.Close( );
Response.Redirect( "WebForm1.aspx" );
}
protected void Reset_Click( object sender, EventArgs e ) {
OleDbConnection conn = new OleDbConnection(
@"Provider=Microsoft.ACE.OleDb.12.0;Data Source=" +
Server.MapPath( "Access\\enrollment.mdb" ) );
String sql = "DELETE FROM courses";
OleDbCommand cmd = new OleDbCommand( sql, conn );
conn.Open( );
cmd.ExecuteNonQuery( );
cmd.Dispose( );
conn.Close( );
Response.Redirect( "WebForm1.aspx" );
}
protected void courseList_SelectedIndexChanged(
object sender, EventArgs e ) {
Result.Text = studentName.Text + " selected the course(s): ";
for ( int i = 0; i < courseList.Items.Count; i++ )
if ( courseList.Items[i].Selected )
Result.Text += " " + courseList.Items[i].Value;
}
}
}
|