【发布时间】:2012-08-06 10:36:05
【问题描述】:
我在我的 asp.net 项目中使用 .mdb 数据库执行存储过程时遇到问题。我想使用存储过程,但是在执行代码之后......
using (OleDbConnection conn = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Database"].ConnectionString.ToString()))
{
conn.Open();
using (OleDbCommand com = new OleDbCommand("Insert", conn))
{
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@Login", UserName0.Text);
com.Parameters.AddWithValue("@Password", Hashing.Hash(ConfirmPassword0.Text));
com.Parameters.AddWithValue("@Role", RoleList1.SelectedValue);
com.ExecuteNonQuery();
}
conn.Close();
我有例外:
System.Data.OleDb.OleDbException:EXECUTE 后的预期查询名称。
但是当我使用下面的代码时,一切正常。 我也改变了:CommandType.StoredProcedure 到 CommandType.Text 但它仍然不起作用。有人可以帮我吗?
using (OleDbConnection conn = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Database"].ConnectionString.ToString()))
{
conn.Open();
using (OleDbCommand com = new OleDbCommand("INSERT INTO Workers ( st_login, st_password, st_role ) VALUES (login, password, role);", conn))
{
com.Parameters.AddWithValue("@Login", UserName0.Text);
com.Parameters.AddWithValue("@Password", Hashing.Hash(ConfirmPassword0.Text));
com.Parameters.AddWithValue("@Role", RoleList1.SelectedValue);
com.ExecuteNonQuery();
}
conn.Close();
【问题讨论】:
-
你有一个名为
Insert的存储过程? -
对于带参数的简单插入,在查询中的每个参数名称前添加@:INSERT INTO Workers (st_login, st_password, st_role) VALUES (@Login, @Password, @Role);