| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 481 人关注过本帖
标题:[求助]页面刷新时数据库表里新插入一条记录和上一条一样的
只看楼主 加入收藏
mq0532
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2006-9-7
收藏
 问题点数:0 回复次数:2 
[求助]页面刷新时数据库表里新插入一条记录和上一条一样的

我用的是 ACCESS 数据库 就用了一个简单的表单 点击 保存后 再刷新页面 库表里就有了两个相同的记录
处理代码我写在了 BUTTON1_CLICK()
PAGE_LOAD()
没写处理的代码
页面刷新时数据库表里新插入一条记录和上一条一样的
请问是怎么回事啊 请高手快给于指点啊

搜索更多相关主题的帖子: 表里 数据库 页面 记录 
2007-04-06 15:39
Kendy123456
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:62
帖 子:2720
专家分:0
注 册:2007-1-3
收藏
得分:0 

你的代码贴出来


2007-04-06 17:36
mq0532
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2006-9-7
收藏
得分:0 

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 = "";

}
}


楼上斑竹 费心了

2007-04-06 18:16
快速回复:[求助]页面刷新时数据库表里新插入一条记录和上一条一样的
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016458 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved