using System;
using System.Collections.Generic;
using
System.Linq;
using System.Web;
using System.Web.UI;
using
System.Web.UI.WebControls;
using System.Data;
using
System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
oledbAccessHelper myacc;
protected void Page_Load(object
sender, EventArgs e)
{
myacc =
new
oledbAccessHelper(Server.MapPath("App_Data/db1.mdb"));
if (!IsPostBack)
{
gridViewBind();
}
}
private
void gridViewBind()
{
string mystr = "select * from
tab1";
DataTable mytab = new
DataTable();
if
(myacc.oledbSqlToDataTable(mystr, ref
mytab))
{
Response.Write("
}
GridView1.DataSource =
mytab;
GridView1.DataBind();
}
private void dataListBind()
{
if (TextBox1.Text.Trim() == "")
return;
string mystr = "select *
from tab1 where ID=@a";
OleDbParameter[] mps
={
new
OleDbParameter("@a",TextBox1.Text.Trim())
};
DataTable mytab = new
DataTable();
if
(myacc.oledbSqlToDataTable(mystr,mps, ref
mytab))
{
Response.Write("
}
DataList1.DataSource =
mytab;
DataList1.DataBind();
return;
}
private void
NameAdd()
{
if (TextBox2.Text.Trim() == "")
return;
string mystr = "insert
into tab1(Name) select @a";
OleDbParameter[] mps
={
new
OleDbParameter("@a",TextBox2.Text.Trim())
};
string mystr1 =
"";
if
(myacc.oledbSqlZhixing(mystr, mps, ref
mystr1))
{
Response.Write("
}
else
{
Response.Write("
}
//gridViewBind();
return;
}
protected void Button1_Click(object sender, EventArgs
e)
{
Button
mbt = (Button)sender;
if (mbt ==
null) return;
if (mbt.ID ==
"Button1")
{
//查询
dataListBind();
}
if (mbt.ID ==
"Button2")
{
//添加
NameAdd();
return;
}
}
}