下面是我的代碼,為什麼連接不了SQL2000並寫不了數據
幫忙啊。。。有亂碼的中文可以不理
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 的摘要描述
/// </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 ??工具?生的程序?
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 此? ASP.NET Web Form ??工具所需的呼叫。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 此???工具支援所必?的方法 - ?勿使用程序???器修改
/// ??方法的?容。
/// </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();
insertCmd.ExecuteNonQuery();
}
catch (Exception ee)
{
Response.write("Fail");
}
finally
{
Conn.Close();
}
Response.write("OK");
}
private void Button1_Click(object sender, System.EventArgs e)
{
string std_model =@"[M][S]*?-[0-9][0-9][0-9][0-9a-zA-Z]";
string std_erp =@"[0-9][0-9][0-9a-zA-Z]";
Regex r = new Regex(std_model);
Match m = r.Match(TextBox1.Text);
if(!m.Success)
Response.Write("<script>alert(\"机种名??入格式不正确,正确格式MS-XXXX\")</script>");
Regex r1 = new Regex(std_erp);
Match m1 = r1.Match(TextBox2.Text);
if(!m1.Success)
Response.Write("<script>alert(\"ERP?入格式不正确,正确格式XXX\")</script>");
Label1.Text="OK";
Response.Write("<script>parent.pb.Button1Complete();parent.ClearTimer();</script>");
savehistory();
}
}
}