用的是C#,請大家幫幫忙using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Data.SqlClient;namespace Fileupload
{
/// <summary>
/// Addhistory ªººK­n´y­z¡C
/// </summary>
public class Addhistory : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Label Label1; private void Page_Load(object sender, System.EventArgs e)
{
Label1.Text=this.Request.QueryString["filename"];
} #region Web Form ³]­p¤u¨ã²£¥Íªºµ{¦¡½X
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: ¦¹¬° ASP.NET Web Form ³]­p¤u¨ã©Ò»Ýªº©I¥s¡C
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// ¦¹¬°³]­p¤u¨ã¤ä´©©Ò¥²¶·ªº¤èªk - ½Ð¤Å¨Ï¥Îµ{¦¡½X½s¿è¾¹­×§ï
/// ³o­Ó¤èªkªº¤º®e¡C
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
private void savehistory()
{
string sModel=TextBox1.Text.ToUpper();
string sERP_NO=TextBox2.Text.ToUpper();
SqlConnection conn = new SqlConnection("data source=(local);user id=sa;password=chrdw;database=test");
SqlCommand cmd = new SqlCommand("insert into VGA(Model,ERP_NO) VALUES('"+sModel+"','"+sERP_NO+"')",conn);
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ee)
{
Response.write("Fail");
}
finally
{
conn.Close();
}
Response.write("OK");
}
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write("<script>parent.pb.Button1Complete();parent.ClearTimer();</script>");
savehistory();
}
}
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Data.SqlClient;namespace Fileupload
{
/// <summary>
/// Addhistory ªººK­n´y­z¡C
/// </summary>
public class Addhistory : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Label Label1; private void Page_Load(object sender, System.EventArgs e)
{
Label1.Text=this.Request.QueryString["filename"];
} #region Web Form ³]­p¤u¨ã²£¥Íªºµ{¦¡½X
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: ¦¹¬° ASP.NET Web Form ³]­p¤u¨ã©Ò»Ýªº©I¥s¡C
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// ¦¹¬°³]­p¤u¨ã¤ä´©©Ò¥²¶·ªº¤èªk - ½Ð¤Å¨Ï¥Îµ{¦¡½X½s¿è¾¹­×§ï
/// ³o­Ó¤èªkªº¤º®e¡C
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
private void savehistory()
{
string sModel=TextBox1.Text.ToUpper();
string sERP_NO=TextBox2.Text.ToUpper();
SqlConnection conn = new SqlConnection("data source=(local);user id=sa;password=chrdw;database=test");
SqlCommand cmd = new SqlCommand("insert into VGA(Model,ERP_NO) VALUES('"+sModel+"','"+sERP_NO+"')",conn);
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ee)
{
Response.write("Fail");
}
finally
{
conn.Close();
}
Response.write("OK");
}
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write("<script>parent.pb.Button1Complete();parent.ClearTimer();</script>");
savehistory();
}
}
}
解决方案 »
- 用javascript实现在上传大附件时,把“请等待,,”换成几个笑话如何实现
- SqlAnyWhere架设的数据库如果通过.net访问到
- 怎样解决“出现用户代码未处理 EntityCommandExecutionException”
- EXECUTE 后的事务计数指出缺少了 COMMIT 或 ROLLBACK TRANSACTION 语句。原计数 = 0,当前计数 = 1
- 高手看看,这句上传图片到指定目录语句有什么错误
- 为什么这些事件无法执行?!
- 字符串局部替换问题。
- asp.net 页面问题
- 如何在datagrid的ItemDataBound事件里的到当前item的datakeyfield的值?
- 怎么用最少的语句判断一个表的内容是否为空?
- net一道项目中做的问题求助^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- 初学者问一个关于自写类库发布的问题
郁悶中。
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
这几句代码没有啥问题。
在这句话设个断点,单步调试看一下哪句出错了
如果我以上的代碼沒錯,請問還有什麼地方有問題呢?例如web.config等
我是通過Button1按扭來調用Savehistory()進行存儲數據的。。
這樣有錯嗎?
最好是跟我的有點像的或是都是用C#的
建议楼主先拉一个控件,诸如dropdownlist,设置一个源,vs2005中会自动为你生成这句连接的话,直接复制过来就可以。
你既然有了
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ee)
{
Response.write("Fail");
}
难道没抛这个异常,此外这个conn.Open(),是不是应该在SqlCommand cmd = new SqlCommand("insert into VGA(Model,ERP_NO) VALUES('"+sModel+"','"+sERP_NO+"')",conn);
上面?
等我回家了,帮你找个例子,手头机器没有相关软件:)
我在網頁上直接運行,並沒報錯,就是數據寫不進SQL2000
郁悶得很我是直接用文本文檔編寫的。。所以沒有VS來進行調試。。
條件有限。。
麻煩你回家後給我個例子謝謝。。
Model varchar(20);
ERP_NO varchar(20)
就這樣子了
被 Response.write("OK");覆盖了建议看看是不是数据库连接有问题。
被 Response.write("OK");覆盖了建议看看是不是数据库连接有问题。
對啊,這是什麼原因呢
{
string sModel=TextBox1.Text.ToUpper();
string sERP_NO=TextBox2.Text.ToUpper();
SqlConnection conn = new SqlConnection("Persist Security Info=False;user id=sa;password=chrdw;data source=david");
SqlCommand cmd = new SqlCommand("insert into VGA(Model,ERP_NO) VALUES('"+sModel+"','"+sERP_NO+"')",conn);
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ee)
{
Response.write("Fail");
}
finally
{
conn.Close();
}
Response.write("OK");
}
這個存儲有問題嗎?請大家給點意見...
然后把这个错误信息发到帖子上