首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

在線等待解決向SQL2000插入數據問題,该如何解决

2012-01-06 
在線等待解決向SQL2000插入數據問題用的是C#,請大家幫幫忙usingSystemusingSystem.CollectionsusingSyst

在線等待解決向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   &ordf;&ordm;&ordm;K&shy;n&acute;y&shy;z&iexcl;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   &sup3;]&shy;p¤u¨&atilde;&sup2;&pound;&yen;&Iacute;&ordf;&ordm;&micro;{&brvbar;&iexcl;&frac12;X
    override   protected   void   OnInit(EventArgs   e)
    {
      //
      //   CODEGEN:   &brvbar;&sup1;&not;°   ASP.NET   Web   Form   &sup3;]&shy;p¤u¨&atilde;&copy;&Ograve;&raquo;&Yacute;&ordf;&ordm;&copy;I&yen;s&iexcl;C
      //
      InitializeComponent();
      base.OnInit(e);
    }
   
    ///   <summary>
    ///   &brvbar;&sup1;&not;°&sup3;]&shy;p¤u¨&atilde;¤&auml;&acute;&copy;&copy;&Ograve;&yen;&sup2;&para;·&ordf;&ordm;¤è&ordf;k   -   &frac12;&ETH;¤&Aring;¨&Iuml;&yen;&Icirc;&micro;{&brvbar;&iexcl;&frac12;X&frac12;s&iquest;è&frac34;&sup1;&shy;×§&iuml;
    ///   &sup3;o&shy;&Oacute;¤è&ordf;k&ordf;&ordm;¤&ordm;&reg;e&iexcl;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();
}


这几句代码没有啥问题。

热点排行