部分代码如下
    string  ModName = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
    string  Price = ((TextBox)e.Item.Cells[3].Controls[0]).Text;    UpdateCommand.CommandText = "INSERT INTO price_list(module, price) VALUES(@module, @price)";
    UpdateCommand.Parameters.Add("@module", OleDbType.VarChar).Value = ModName;
    UpdateCommand.Parameters.Add("@price", OleDbType.Single).Value = Price;
    myConnection.Open();
    UpdateCommand.ExecuteNonQuery();
意图是从网页表单里填的东西添加到数据库记录。我用Access数据库,表格只有两个字段(字符型module,小数型price)。结果一运行就说inser into 语句语法错误。
我是上个星期开始接触ASP.NET的,如果还需要提供什么信息,请告知。

解决方案 »

  1.   

    如果不写成存储过程的话,SQL insert语句好象不能有参数。
    不知道是不是,也请高手指教。
      

  2.   

    UpdateCommand.CommandText = "INSERT INTO price_list  (module, price) VALUES(@module, @price)";
      

  3.   

    应该是InsertCommand.CommandText= "INSERT INTO price_list(module, price) VALUES(@module, @price)";
      

  4.   

    price_list和(module, price)这间加个空格试试。多来这里转转你就知道了。:)
      

  5.   

    你用方括括起来试试看。保不准,你用的有些是access关键字。其实,你应该用trace把错误信息贴写出来。那样才利于解决问题。
      

  6.   

    没有必要用参数吧!
    请必成这样试试看,其中UpdateCommand.ActoinConnection中的ActoinConnection可能写错了。它的意思就是:设一UpdateCommand使用那个联接
    string  ModName = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
        string  Price = ((TextBox)e.Item.Cells[3].Controls[0]).Text;    UpdateCommand.CommandText = "INSERT INTO price_list(module, price) VALUES(ModName, Price )";
        //UpdateCommand.Parameters.Add("@module", OleDbType.VarChar).Value = ModName;
        //UpdateCommand.Parameters.Add("@price", OleDbType.Single).Value = Price;
       
        myConnection.Open();
        UpdateCommand.ActoinConnection=myConnection;
        UpdateCommand.ExecuteNonQuery();
      

  7.   

    UpdateCommand.CommandText = "INSERT INTO price_list(module, price) VALUES(@module, @price)";
        UpdateCommand.Parameters.Add(new OleDbParameter("@module", OleDbType.VarChar));
        UpdateCommand.Parameters["@module"].Value = ModName;
        UpdateCommand.Parameters.Add(new OleDbParameter("@price", OleDbType.Single));
        UpdateCommand.Parameters["@price"].Value = Price;
        myConnection.Open();
        UpdateCommand.ExecuteNonQuery();