I want to be able to call a stored proc with named parameters in PetaPoco.
In order to call a stored proc that does a search/fetch:
Can I do something like this:
return db.Fetch<Customer>("EXEC SP_FindCust", new SqlParameter("@first_name", fName), new SqlParameter("@last_name", lName), new SqlParameter("@dob", dob));
Also, how can I call a stored proc that does an insert?
return db.Execute("EXEC InsertCust @CustID = 1, @CustName = AAA")
Thanks, Nac
Expand the database that you want, expand Programmability, and then expand Stored Procedures. Right-click the user-defined stored procedure that you want and select Execute Stored Procedure. In the Execute Procedure dialog box, specify a value for each parameter and whether it should pass a null value.
You can also pass parameters to a stored procedure, so that the stored procedure can act based on the parameter value(s) that is passed.
The easy way is to right-click on the procedure in Sql Server Management Studio (SSMS), select 'Execute stored procedure..." and add values for the input parameters as prompted. SSMS will then generate the code to run the procedure in a new query window, and execute it for you.
You can call an SQL stored procedure with the execute, open, or get statement; in each case, you use the #sql directive. A stored procedure is a set of instructions for a database, like a function in EGL.
Update:
I tried the following for fetch and insert and it worked perfectly:
var s = PetaPoco.Sql.Builder.Append("EXEC SP_FindCust @@last_name = @0", lname); s.Append(", @@first_name = @0", fName); s.Append(", @@last_name = @0", lName); s.Append(", @@dob = @0", dob); return db.Query<Cust>(s);
This can be improved further to pass SQL parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With