Quantcast
Channel: Editor — DataTables forums
Viewing all articles
Browse latest Browse all 3800

Is Database.Sql() the recommended method for executing SQL Server Stored procedures

$
0
0

I am trying to execute a SQL Server stored procedure after a particular field is updated via inline editing.

Looking through the .NET Libraries API Documentation, I found a potential method Database.Sql().

While the code shown below works in my case (C# MVC 5 and SQL Server) My question is whether use of Database.Sql() is the optimal method for executing a stored procedure. I just wanted to make sure there wasn't a better method available that I missed in the documentation.

The overall code is inspired by the Events (.NET) page.

      response.PostEdit += (sender, e) => ForwardPopulate(db,e.Id,e.Values);

Where ForwardPopulate is a custom function that executes the SQL Server stored procedure.

private static void ForwardPopulate(Database db, object id, Dictionary<string, object> values)
{
    // ... code ...

    // ... sp is the T-SQL method string for executing a stored procedure  ...
    var sp = $"exec dbo.TestTable {param1},{param2},'{param3}',{param4},'{param5}';";

        // execute stored procedure
    db.Sql(sp);
}

Viewing all articles
Browse latest Browse all 3800

Trending Articles