This topic is locked
[SOLVED]

 How do I call a SQL Server Stored Procedure with parameters

9/15/2020 10:31:06 AM
ASPRunner.NET General questions
D
DWill author

How do I call a SQL Server Stored Procedure with parameters? The "Help" manual is not very helpful. I can get the following to build successfully. However, I need to be able to pass in a parameter. Please Help!!!
return DB.Query("EXEC usp_SearchForFinanceInvoicesDocuments");
--------------

The Help manual gives the following examples:

Example 1: tDal.CustomerQuery("EXEC usp_SearchForFinanceInvoicesDocuments");
Error: error CS0103: The name 'tDal' does not exist in the current context
Example 2: tDAL.CustomQuery("EXEC usp_SearchForFinanceInvoicesDocuments '" + values[12345] + "'");

Error: error CS0103: The name 'values' does not exist in the current context

admin 9/15/2020

Did you try the hard-coded value instead of using values array?
You can blame the manual all day long but you cannot even copy and paste it properly. There is no such thing as CustomerQuery, the correct function name is CustomQuery.
Also, if manual says you need to use values["FieldName"].ToString() you cannot replace it with values[12345] which is meaningless. Test your SQL query outside of ASPRunner.NET first, make sure it works and then copy and paste it into your code. This is what hardcoded means. Once it works you can replace the hardcoded value of the parameter with the variable.
More info:

https://xlinesoft.com/asprunnernet/docs/how_to_execute_stored_procedures_from_events.htm

D
DWill author 9/16/2020



Did you try the hard-coded value instead of using values array?
You can blame the manual all day long but you cannot even copy and paste it properly. There is no such thing as CustomerQuery, the correct function name is CustomQuery.
Also, if manual says you need to use values["FieldName"].ToString() you cannot replace it with values[12345] which is meaningless. Test your SQL query outside of ASPRunner.NET first, make sure it works and then copy and paste it into your code. This is what hardcoded means. Once it works you can replace the hardcoded value of the parameter with the variable.
More info:

https://xlinesoft.com/asprunnernet/docs/how_to_execute_stored_procedures_from_events.htm


First off, No Need to be Rude & Condescending and I'm Not blaming the manual! I'm simply asking for guidance, as I may be missing something or not interpreting the manual correctly. Secondly, you're right! I didn't copy & paste it properly because I re-typed it, but maybe I should have copy & pasted it. That was my badd. Furthermore; I know what hardcoded means and in my code, I have tried both ways (i.e. hardcoded & w/a variable) and I removed the ".ToString()" to test it that way as well since it's a number. I've simply attempted to adjust the code multiple ways before reaching out for help. Finally, YES I have successfully tested the query in SQL multiple times.
Anyway, as I stated, I was reaching out for more guidance and not to be talked down to and/or demeaned. So, I will simply continue to try to figure this thing out and in attempt to not miss my deadline. Thank you for your assistance.

admin 9/16/2020

Just start with the hardcoded SQL query that contains your stored procedure call. Things are always a bit easier once you got the most basic example working.

jadachDevClub member 9/16/2020

Here is a sample passing 2 parameters. Make sure the order matches your stored procedure.

tDAL.CustomQuery("EXEC dbo.ImportProviderPreferences '" + keys["ProviderID"].ToString() + "','" + XSession.Session["UserID"].ToString() + "'");