Calling SQL Functions directly from C#

后端 未结 6 761
遇见更好的自我
遇见更好的自我 2021-02-08 12:49

I have a requirement to run a query against a database that will return either a zero or one (Checking for existance of specific criteria). The Tech specs I\'ve been given for r

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-08 13:01

    Execute the Stored Procedure using the ExecuteScalar() method. You can then cast the result of this to a boolean.

    e.g

       SqlConnection con = new SqlConnection(connectionString);
        SqlCommand com = new SqlCommand("Execute dbo.usp_MyStoredProc", con);
        return (Boolean)com.ExecuteScalar();
    

提交回复
热议问题