PDA

View Full Version : Stored Procedure Usage


Iggy
04-25-2007, 08:39 PM
Hi,
Is it possible to use stored procedures via AdoTemplate.QueryWithRowCallbackDelegate? Or do we have to create a class deriving from Spring.Data.Objects.StoredProcedure?

Here is a code snippet of what I'm trying to do, and the resulting error is that the sql server errors out that the stored procedure requires a parameter which is missing.

What I want the code to do:
exec dbo.[select_user_by_user_name] @UserName = 'blah'

My C# code snippet:
AdoTemplate.QueryWithRowCallbackDelegate(CommandTy pe.StoredProcedure, "dbo.[select_user_by_user_name]",
delegate(IDataReader dataReader)
{
if(dataReader.Read())//expect only one result
{
//do some assignments here, user is defined outside, etc
user.FirstName = dataReader["First Name"] as string;
user.LastName = dataReader["Last Name"] as string;
user.Email = dataReader["Email"] as string;
user.Enabled = dataReader.GetBoolean(dataReader.GetOrdinal("IsEnabled"));
}
}
, "@User_Name", DbType.String, 50, "blah");

The database complaint:
Procedure or Function 'select_user_by_user_name' expects parameter '@User_Name', which was not supplied.

Any ideas or help will be greatly appreciated. :)

Erich Eichinger
04-25-2007, 09:02 PM
Hi,

try to remove the leading @ from the parameter name:


...
, "User_Name", DbType.String, 50, "blah");
...



cheers,
Erich

Iggy
04-25-2007, 09:18 PM
Awesome! The sproc ran, unfortunately the assignments aren't happening inside the anonymous method, but that's a separate issue which I'll take a look at. Thanks a lot Eric! :)

Iggy
04-25-2007, 09:19 PM
Actually I figured it out, the very first read of the data reader is already called by spring so I don't have to call it. Thanks!