用的是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();
  }
    
}
}

解决方案 »

  1.   

    就是我上面的代碼不能向sql2000寫入數據
    郁悶中。
      

  2.   

    SqlCommand cmd = new SqlCommand("insert into VGA(Model,ERP_NO) VALUES('"+sModel+"','"+sERP_NO+"')",conn);
            try  
             {  
              conn.Open();
              cmd.ExecuteNonQuery();
             }  
    这几句代码没有啥问题。
      

  3.   

    SqlConnection conn = new SqlConnection("data source=(local);user id=sa;password=chrdw;database=test");
    在这句话设个断点,单步调试看一下哪句出错了
      

  4.   

    SqlConnection conn = new SqlConnection("data source=(local);user id=sa;password=chrdw;database=test");這話是正確的嗎?
    如果我以上的代碼沒錯,請問還有什麼地方有問題呢?例如web.config等
    我是通過Button1按扭來調用Savehistory()進行存儲數據的。。
    這樣有錯嗎?
      

  5.   

    或者說大家有沒有向sql2000插入數據的例子或代碼嗎?
    最好是跟我的有點像的或是都是用C#的
      

  6.   

    你把执行数据库方法放在response前面啊。可能运行时问题吧。
      

  7.   

    如果是SqlConnection conn = new SqlConnection("data source=(local);user id=sa;password=chrdw;database=test");出错的话,
    建议楼主先拉一个控件,诸如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);
    上面?
    等我回家了,帮你找个例子,手头机器没有相关软件:)
      

  8.   

    對大家的支持不勝感激。。
    我在網頁上直接運行,並沒報錯,就是數據寫不進SQL2000
    郁悶得很我是直接用文本文檔編寫的。。所以沒有VS來進行調試。。
    條件有限。。
      

  9.   

    cosmos_sjtu() 先生,我將conn open()放在前面了也是用不了。。呵呵
    麻煩你回家後給我個例子謝謝。。
      

  10.   

    數據庫Test,表VGA:
    Model varchar(20);
    ERP_NO varchar(20)
    就這樣子了
      

  11.   

    ("data source=(local);user id=sa;password=chrdw;database=test");、、("server=(local);user id=sa;password=chrdw;database=test");
      

  12.   

    是不是抛了异常,但是异常信息Response.write("Fail");  
    被  Response.write("OK");覆盖了建议看看是不是数据库连接有问题。
      

  13.   

    是不是抛了异常,但是异常信息Response.write("Fail");  
    被  Response.write("OK");覆盖了建议看看是不是数据库连接有问题。
    對啊,這是什麼原因呢
      

  14.   

    private void savehistory()
            { 
             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");
            }
            
    這個存儲有問題嗎?請大家給點意見...
      

  15.   

    Response.write("Fail");  改成  Response.write(ee.ToString());
    然后把这个错误信息发到帖子上