Using system;
Using system. Data;
Using system. configuration;
Using system. collections;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. Data. oledb;
Public partial class html_test_execl: system. Web. UI. Page
......{
Static string connectionstring = "provider = Microsoft. Jet. oledb.4.0; Data Source =" + httpcontext. Current. server. mappath ("~ /Html/") +" new.xls; extended properties = Excel 8.0 ;";
Protected void page_load (Object sender, eventargs E)
......{
}
Protected void btnadonet_createexecle_click (Object sender, eventargs E)
......{
Oledbconnection Cn = new oledbconnection (connectionstring );
CN. open ();
Oledbcommand cmd = new oledbcommand ();
Cmd. Connection = cn;
Cmd. commandtext = "create table mytable (firstname char (255), lastname char (255 ))";
Cmd. executenonquery ();
Cmd. commandtext = "insert into mytable (firstname, lastname) values ('liao', 'haibing ')";
Cmd. executenonquery ();
Cmd. commandtext = "insert into mytable (firstname, lastname) values ('liao ', 'haibing ')";
Cmd. executenonquery ();
Cmd. commandtext = "create table mytable2 (name char (255), address char (255 ))";
Cmd. executenonquery ();
CN. Close ();
}
Protected void btnshowexecl_content_click (Object sender, eventargs E)
......{
Showexeclcontent ();
}
Private void showexeclcontent ()
......{
Oledbconnection Cn = new oledbconnection (connectionstring );
Oledbdataadapter DDA = new oledbdataadapter ("select * from [mytable]", CN );
Dataset DS = new dataset ();
DDA. Fill (DS, "mytable ");
Datagrid1.datasource = Ds. Tables ["mytable"]. defaultview;
Datagrid1.databind ();
}
Protected void btninsertexecl_click (Object sender, eventargs E)
......{
Insertexecldate ();
Showexeclcontent ();
}
Private void insertexecldate ()
......{
String executestring = "insert into mytable (firstname, lastname) values ('" + this.txt firstname. text. trim () + "','" + txtlastname. text. trim () + "')";
This. update_insert_delete_operator (executestring );
}
Protected void btnupdateselect_click (Object sender, eventargs E)
......{
Updateselect(this.txt firstname. Text. Trim (), this.txt lastname. Text. Trim ());
Showexeclcontent ();
}
Private void updateselect (string firstname, string lastname)
......{
String executestring = "Update mytable set lastname = '" + lastname + "'where firstname ='" + firstname + "'";
This. update_insert_delete_operator (executestring );
}
/** // The deletion operation cannot be performed, prompting that isam does not support data deletion in the chain table. I wonder if there is any way to solve this problem.
Protected void btndelete_click (Object sender, eventargs E)
......{
Delete(this.txt firstname. Text. Trim ());
Showexeclcontent ();
}
Private void Delete (string firstname)
......{
String executestring = "delete from mytable where firstname = '" + firstname + "'";
This. update_insert_delete_operator (executestring );
}
Private void update_insert_delete_operator (string executestring)
......{
Oledbconnection Cn = new oledbconnection (connectionstring );
CN. open ();
Oledbcommand cmd = new oledbcommand (executestring, CN );
Cmd. executenonquery ();
CN. Close ();
}
}