I write this function in SQL:
ALTER FUNCTION Fn_CheckBill
(
@image AS image,
@number AS nvarchar(50),
@date AS nchar(10)
)
RETURNS bit
AS
BEGIN
DECLARE @flag bit;
IF EXISTS ( SELECT *
FROM tblBill
WHERE ((cast([Image] as varbinary(max)) = cast(@image as varbinary(max))) AND (Number = @number) AND ([Date] = @date)) )
BEGIN
SET @flag = 0
END
ELSE
BEGIN
SET @flag = 1
END
RETURN @flag
END
And write this code in my C# source code:
int flag;
try
{
objCommand = new SqlCommand("SELECT Fn_CheckBill(@image,@date,@number) AS int");
objCommand.CommandType = CommandType.Text;
objCommand.Parameters.AddWithValue("image", image);
objCommand.Parameters.AddWithValue("number", number);
objCommand.Parameters.AddWithValue("date", _Date);
using (objConnection = new SqlConnection(connenctString))
{
objConnection.Open();
objCommand.Connection = objConnection;
flag = int.Parse(objCommand.ExecuteScalar().ToString());
}
if (flag == 1)
{
return true;
}
else
{
return false;
}
}
catch
{
return false;
}
But It throw this exception when executed: 'Fn_CheckBill' is not a recognized function name.
Please help me to solve this problem :(
ntext,text, andimagedata types will be removed in a future version of SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Usenvarchar(max),varchar(max), andvarbinary(max)instead. See details here