我用的是 ACCESS 数据库 就用了一个简单的表单 点击 保存后 再刷新页面 库表里就有了两个相同的记录
处理代码我写在了 BUTTON1_CLICK()
PAGE_LOAD()
没写处理的代码
页面刷新时数据库表里新插入一条记录和上一条一样的
请问是怎么回事啊 请高手快给于指点啊
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 sr : System.Web.UI.Page
{
private readonly string AccessConnectionString=ConfigurationSettings.AppSettings["AccessConnectionString"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ms1.Text = "";
ks2.Text = "";
dks3.Text = "";
kbs4.Text = "";
price1.Text = "";
price2.Text = "";
price3.Text = "";
price4.Text = "";
date1.Text = "";
}
}
protected void save_Click(object sender, EventArgs e)
{
string num1 = ms1.Text.Trim();
// string num2 = ks2.Text.Trim();
//string num3 = dks3.Text.Trim();
//string num4 = kbs4.Text.Trim();
string per1 = price1.Text.Trim();
// string per2 = price2.Text.Trim();
// string per3 = price3.Text.Trim();
// string per4 = price4.Text.Trim();
double total1 = (Convert.ToDouble(num1)) * (Convert.ToDouble(per1));
//double total2 = Convert.ToDouble(num2) * Convert.ToDouble(per2);
//double total3 = Convert.ToDouble(num3) * Convert.ToDouble(per3);
//double total4 = Convert.ToDouble(num4) * Convert.ToDouble(per4);
string total = Convert.ToString(total1);
//string total2 = Convert.ToString(total2);
//string total3 = Convert.ToString(total3);
//string total4 = Convert.ToString(total4);
//DateTime date = Convert.ToDateTime(date1.Text.Trim());
string accessString = AccessConnectionString + Server.MapPath("csc.mdb");
OleDbConnection accessConn = new OleDbConnection(accessString);
try
{
accessConn.Open();
string CmdText = "insert into sr(price) values('"+total+"')";
OleDbCommand myCommand = new OleDbCommand(CmdText,accessConn);
myCommand.ExecuteNonQuery();
accessConn.Close();
Response.Redirect("sr.aspx");
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
ms1.Text = "";
ks2.Text = "";
dks3.Text = "";
kbs4.Text = "";
price1.Text = "";
price2.Text = "";
price3.Text = "";
price4.Text = "";
date1.Text = "";
}
protected void reset_Click(object sender, EventArgs e)
{
ms1.Text = "";
ks2.Text = "";
dks3.Text = "";
kbs4.Text = "";
price1.Text = "";
price2.Text= "";
price3.Text = "";
price4.Text = "";
date1.Text = "";
}
}
楼上斑竹 费心了