MySQL stored procedure with .NET connector issue
I have seen other threads that address this error, but nothing seems to fit my situation.
First of all, my code works completely fine when I run it locally.
But when I upload it to the server, I get the error:
The parameter '? PuserName 'was not found in the collection.
Here is the C # code:
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 code:
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;
+1
source to share