Last post Apr 08, 2020 02:36 AM by Yang Shen
Apr 07, 2020 07:27 PM|rkrex|LINK
I am trying to do something I would think would be extremely easy. Maybe I have got so used to using the entity framework, but I just want to return data from a stored procedure that receives one parameter usining plain old ADO.NET. I dont know
what in the world I could be doing wrong but should I enclose the name of my stored procedure in brackets within the SqlCommand like this var command =
new SqlCommand("[dbo].[spGetSSN]", connection) or remove the brackets? And is this how I add a parameter to the stored procedure...... command.Parameters.Add(new
SqlParameter("ssn", model.SSN)); or do I need a @ sign before the ssn like @ssn? This seems extremely simplistic but for some reason it's not working. Thanks for any HELP !!!
Apr 07, 2020 08:08 PM|mgebhard|LINK
The official ADO.NET docs has examples.
I would start by going through the source examples. If you still need help, share your actual source code.
Apr 07, 2020 08:56 PM|rkrex|LINK
This is an example of how my colleague performed a delete operation, but I need to pull some data in. Thanks !!!
public ActionResult RemoveSSN(RemoveSSN.Models.RemoveSSNModel model)
using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[model.connectionString].ConnectionString))
using (var command = new SqlCommand("[dbo].[spRemoveSSN]", connection)
CommandType = CommandType.StoredProcedure
command.Parameters.Add(new SqlParameter("ssn", model.SSN));
message = "SSN successfully deleted.";
status = "success";
Apr 07, 2020 09:02 PM|mgebhard|LINK
The link in my first post shows how to create parameter queries with code examples. Your colleague's examples shows how to execute a stored procedure with parameters. Both are patterns that you should be able to reuse by substituting your SQL script.
I think it's a good idea to meet with your colleagues and ask for assistance in this matter.
Apr 07, 2020 09:21 PM|rkrex|LINK
Thank You !!!!
Apr 08, 2020 02:36 AM|Yang Shen|LINK
If the issue has beedn resolved and @mgebhard's post is helpful, please mark his post as the answer, this could help those who met the same issue to easily find the solution.