我明明传入了参数 为什么提示没有参数 VS中用sql存储过程
publicclassUserDao{privatereadonlystringconnStr="DataSource=.;InitialCatalog=DB_userD...
public class UserDao
{
private readonly string connStr = "Data Source=.;Initial Catalog=DB_userDemo;User ID=sa;Password=sa";
/*
create proc proc_addUser
@loginName varchar(50),
@loginPwd varchar(50)
as
INSERT INTO tb_user (loginName,loginPwd) VALUES (@loginName,@loginPwd)
go
*/
public int InsertUser(User user)
{
int result = 0;
using (SqlConnection connection = new SqlConnection(connStr))
{
SqlCommand command = new SqlCommand("proc_addUser", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@loginName", user.LoginName);
command.Parameters.AddWithValue("@loginPwd", user.LoginPwd);
connection.Open();
result = command.ExecuteNonQuery();
connection.Close();
}
return result;
}
}
错误:
过程或函数 'proc_addUser' 需要参数 '@loginName',但未提供该参数。
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: 过程或函数 'proc_addUser' 需要参数 '@loginName',但未提供该参数。
Source Error:
Line 32: command.Parameters.AddWithValue("@loginPwd", user.LoginPwd);
Line 33: connection.Open();
Line 34: result = command.ExecuteNonQuery();
Line 35: connection.Close();
Line 36: } 展开
{
private readonly string connStr = "Data Source=.;Initial Catalog=DB_userDemo;User ID=sa;Password=sa";
/*
create proc proc_addUser
@loginName varchar(50),
@loginPwd varchar(50)
as
INSERT INTO tb_user (loginName,loginPwd) VALUES (@loginName,@loginPwd)
go
*/
public int InsertUser(User user)
{
int result = 0;
using (SqlConnection connection = new SqlConnection(connStr))
{
SqlCommand command = new SqlCommand("proc_addUser", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@loginName", user.LoginName);
command.Parameters.AddWithValue("@loginPwd", user.LoginPwd);
connection.Open();
result = command.ExecuteNonQuery();
connection.Close();
}
return result;
}
}
错误:
过程或函数 'proc_addUser' 需要参数 '@loginName',但未提供该参数。
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: 过程或函数 'proc_addUser' 需要参数 '@loginName',但未提供该参数。
Source Error:
Line 32: command.Parameters.AddWithValue("@loginPwd", user.LoginPwd);
Line 33: connection.Open();
Line 34: result = command.ExecuteNonQuery();
Line 35: connection.Close();
Line 36: } 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询