Skip to content
Advertisement

How to declare sql variable in C#

My requirement is to remove all record but one from a table. For this I am executing a series of two different sql commands. Seems like on ssms it works fine but with C# is not

My qsns

  1. How can I declare a sql variable correctly in C# (see ClearData method)
  2. And, how to execute multiple queries in a single query string?(if I am doing this right)

EDIT

I came up with this to accomplish this. But still now luck. Please advise me to what to do:

Advertisement

Answer

Maybe this can help you, change your query (queryToExec) with:

if the declared variable is the problem you can troubleshoot with this, is not the best query, but whatever that you are using is not the best form neither :P.

I’m adding a 0 rows validation, in other way the sp crashed when no data found.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement