部分代码如下
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的,如果还需要提供什么信息,请告知。
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的,如果还需要提供什么信息,请告知。
不知道是不是,也请高手指教。
请必成这样试试看,其中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();
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();