1
我已经看到了其他处理这个错误的主题,但没有一个与我的情况相符。与.NET连接器问题的mySQL存储过程
首先,当我在本地运行它时,我的代码完全正常工作。
但是,当我把它上传到服务器,我得到的错误:“?PuserName”
参数集合中没有找到。
下面是C#代码:
public DataSet GetEmployeeByUsername(string username)
{
string proc = "schema.GetEmployeeByUsername";
MySqlParameter[] args = new MySqlParameter[1];
args[0] = new MySqlParameter("?PuserName", MySqlDbType.VarChar);
args[0].Value = username;
return SQLDatasetCall(args, proc);
}
protected DataSet SQLDatasetCall(MySqlParameter[] sqlparams, string call)
{
string myConString = ConfigurationManager.AppSettings["mySql"];
MySqlConnection MyConnection = new MySqlConnection(myConString);
MySqlDataAdapter adapter = new MySqlDataAdapter();
MyConnection.Open();
MySqlCommand command = new MySqlCommand(call, MyConnection);
command.CommandType = CommandType.StoredProcedure;
if (sqlparams != null)
{
foreach (MySqlParameter param in sqlparams)
{
command.Parameters.Add(param);
}
}
DataSet ds = new DataSet();
adapter.SelectCommand = command;
adapter.Fill(ds);
adapter.Dispose();
MyConnection.Close();
return ds;
}
SQL代码:
delimiter |
create procedure GetEmployeeByUsername(in PuserName varchar(45))
begin
select id,
firstName,
lastName,
phone,
address1,
address2,
city,
state,
zip,
username,
password,
emptypeid
from schema.tblemployees
where
username=PuserName;
end |
delimiter;
我有类似的问题两次。一种解决方案是从Web服务器上删除项目并重新发布。第二个解决方案是删除所有表单bin目录并重新构建。 – 2009-01-04 04:42:52