1. Class1.cs
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Data. OleDb;
Using System. Data;
Namespace Mane
{
Public class Class1
{
Public DataTable selectTable (string sqltext, OleDbConnection con)
{
DataTable dt = new DataTable ();
OleDbDataAdapter adp = new OleDbDataAdapter (sqltext, con );
Adp. Fill (dt );
Return dt;
}
Public void selectcmd (string sqltext, OleDbConnection con)
{
OleDbCommand cmd = con. CreateCommand ();
Cmd. CommandText = sqltext;
Try
{
Con. Open ();
Cmd. ExecuteNonQuery ();
}
Catch (Exception e)
{
Throw new SystemException (e. Message );
}
Finally
{
Con. Close ();
}
}
}
}
2. news_add.aspx.cs
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Data. oledb;
Using mane;
Using system. Data;
Namespace mane. Admin
{
Public partial class webform2: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
}
Protected void button#click (object sender, EventArgs e)
{
If (! Request. IsAuthenticated)
{
Response. Redirect (Server. MapPath ("Login_Admin.aspx "));
}
Else
{
// Add
Class1 Cl = new class1 ();
Oledbconnection con = new oledbconnection (@ "provider = Microsoft. Jet. oledb.4.0; Data Source =" + @ server. mappath ("/app_data/db1.mdb "));
String sqlstr = "insert into news (title, author, body, date) values ('" + textbox1.text. Trim () + "', '" + textbox2.text. Trim () +
"','" + Freetextbox1.text + "','" + datetime. Now. tow.datestring () + "')";
Cl. selectcmd (Sqlstr, con );
// Refresh
System. Web. HttpContext. Current. Response. Write ("<script language = javascript> alert ('success! '); </Script> ");
}
}
}
}