Parameter["@xxx"] does not have a default value

G

Guest

I keep getting this error message and cannot find the solution for it. I've
written the following stored procedure:

SELECT Username
FROM [User]
WHERE Username=[@Username];

When I run the stored procedure within Access, it works. However, the
following code does not work. The field in the Access table is set to: Text
and has Required: yes. Any suggestions?

public static bool CheckUsername(string name){
bool success = false;
try{
using(OleDbConnection conn = new
OleDbConnection(BroodmoorBase.CONNECTION_STRING)){
conn.Open();
OleDbCommand cmd = new OleDbCommand("bspCheckUsername",conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new OleDbParameter("@Username",OleDbType.Char,50));
cmd.Parameters["@Username"].Value = name;

if( cmd.ExecuteNonQuery() > 0 )
success = true;

conn.Close();
return success;
}//end using
}
catch(Exception e){ throw e; }
}

I've tried putting a breakpoint immediately before the 'if' statement to
see if there is indeed a value for the parameter. There is. Sometimes, the
statement conn.Close() doesn't even execute as I step through the code. It
just skips that line and executes the 'return success;' statement.

I'm using Access and I'm using .NET Framework 1.0.

I've checked the spelling in the strored procedure and my code and it is
the same. Any help would be appreciated.

thanks,
Prince
 
G

Guest

It's funny. I decided to change the stored procedure to:
SELECT Count(User.Username)
FROM [User]
WHERE Username=[@Username];


I then changed the code to:
int count = (int)cmd.ExecuteScalar();
if( count > 0 )
success = true;

everything works. There is no more problem with parameters not having a
default value. I would still like to know why that problem occurs and the
solution for it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top