我已经看过其他主题来处理这个错误,但似乎没有一个与我的情况相符。
首先,当我在本地运行时,我的代码完全正常。
但是当我将它上传到服务器时,我收到错误:
在集合中找不到参数'?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;
答案 0 :(得分:1)
原来微软Visual Web Developer在“发布”方法中没有正确地对我的文件进行ftp。我再次下载了filezilla和ftp-ed文件,它起作用....