How to execute sql user defined function using c#? -
how execute sql user defined function using c# same of executing stored procedure
you can use other sql. here's example:
using (var con = new sqlconnection(properties.settings.default.connectionstring)) using (var cmd = new sqlcommand("select dbo.isinteger(@value);", con)) { con.open(); cmd.parameters.add("@value", sqldbtype.varchar).value = "10"; bool isint = (bool)cmd.executescalar(); }
dbo.isinteger
scalar-valued function returns bit
(true/false).
for sake of completeness , if it's not related, here it:
create function [dbo].[isinteger](@value varchar(18)) returns bit begin return isnull( (select case when charindex('.', @value) > 0 case when convert(int, parsename(@value, 1)) <> 0 0 else 1 end else 1 end isnumeric(@value + 'e0') = 1), 0) end
Comments
Post a Comment