读书人

在等待解向SQL2000插入,该

发布时间: 2012-01-06 22:55:18 作者: rapoo

在等待解向SQL2000插入
用的是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();
}

}
}



[解决办法]
SqlCommand cmd = new SqlCommand( "insert into VGA(Model,ERP_NO) VALUES( ' "+sModel+ " ', ' "+sERP_NO+ " ') ",conn);
try
{
conn.Open();
cmd.ExecuteNonQuery();
}


这几句代码没有啥问题。

读书人网 >asp.net

热点推荐