using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//GridView1.DataSource = bind();
//GridView1.DataBind();
GridView1.DataSource = bindtable();
GridView1.DataBind();
}
}
private DataSet bind()
{
OleDbConnection conn = new OleDbConnection("provider=Microsoft.jet.oledb.4.0;data source=|datadirectory|fazhi.mdb");
OleDbCommand comm = new OleDbCommand("select * from pa", conn);
OleDbDataAdapter database = new OleDbDataAdapter(comm);
DataSet ds = new DataSet();
conn.Open();
database.Fill(ds);
return ds;
}
private DataTable bindtable()
{
OleDbConnection conn = new OleDbConnection("provider=Microsoft.jet.oledb.4.0;data source=|datadirectory|fazhi.mdb");
conn.Open();
OleDbCommand cmd = new OleDbCommand("select * from pa order by id desc", conn);
OleDbDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
DataTable dt = new DataTable();
dt.Load(sdr);
return dt;
conn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection("provider=Microsoft.jet.oledb.4.0;data source=|datadirectory|fazhi.mdb");
conn.Open();
OleDbCommand cmd = new OleDbCommand("insert into pa(xxmc) values(‘" + TextBox1.Text + "‘)", conn);
cmd.ExecuteNonQuery();
OleDbCommand comm = new OleDbCommand("select * from pa order by id desc",conn);
OleDbDataReader sdr = comm.ExecuteReader(CommandBehavior.CloseConnection);
DataTable dt = new DataTable();
dt.Load(sdr);
GridView1.DataSource = dt;
GridView1.DataBind();
conn.Close();
}
}