protected void Button1_Click(object sender, EventArgs e)
{
string name = txtCatalogName.Text.ToString().Trim();
if (name.Length < 1)
{
lblerror.Text = "类别不能为空!";
return;
} OleDbConnection MyConn;
MyConn = new OleDbConnection(ConfigurationManager.AppSettings["myconnstring"].ToString() + System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["mydbpath"]));
MyConn.Open();
string cmdText = "INSERT INTO AboutCatalogs(CatalogName)VALUES('" + name + "')";
OleDbCommand myCommand = new OleDbCommand(cmdText, MyConn);
myCommand.ExecuteNonQuery(); cmdText = "select CatalogId,CatalogName from AboutCatalogs order by CatalogId asc";
OleDbDataAdapter da = new OleDbDataAdapter(cmdText, MyConn);
DataSet ds = new DataSet();
da.Fill(ds, "AboutCatalogs");
GridView1.DataSource = ds.Tables["AboutCatalogs"].DefaultView;
GridView1.DataBind();
RecordCount.Text = ds.Tables[0].Rows.Count.ToString(); txtCatalogName.Text = "";
}我用这个添加完数据,再刷新一下他又会再出来一条,一直刷新一直添加重复的数据,什么原因
{
string name = txtCatalogName.Text.ToString().Trim();
if (name.Length < 1)
{
lblerror.Text = "类别不能为空!";
return;
} OleDbConnection MyConn;
MyConn = new OleDbConnection(ConfigurationManager.AppSettings["myconnstring"].ToString() + System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["mydbpath"]));
MyConn.Open();
string cmdText = "INSERT INTO AboutCatalogs(CatalogName)VALUES('" + name + "')";
OleDbCommand myCommand = new OleDbCommand(cmdText, MyConn);
myCommand.ExecuteNonQuery(); cmdText = "select CatalogId,CatalogName from AboutCatalogs order by CatalogId asc";
OleDbDataAdapter da = new OleDbDataAdapter(cmdText, MyConn);
DataSet ds = new DataSet();
da.Fill(ds, "AboutCatalogs");
GridView1.DataSource = ds.Tables["AboutCatalogs"].DefaultView;
GridView1.DataBind();
RecordCount.Text = ds.Tables[0].Rows.Count.ToString(); txtCatalogName.Text = "";
}我用这个添加完数据,再刷新一下他又会再出来一条,一直刷新一直添加重复的数据,什么原因
http://topic.csdn.net/u/20080920/14/1e3905a2-b355-4565-bba3-e441180752bd.html
page_load()
{
if(!IsPostBack)
{
Session["first"] = true;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if(Session["first"] == null)
{
return;
}
//添加数据代码
...Session["first"] = null;
...
}