I need to search a SQL table in C# for a value(filename). If it existed return TRUE and if not return FALSE and continue my code based on that.
This is what I have but it's not working:
SqlCommand cmdName = new SqlCommand("SELECT CASE WHEN EXISTS (SELECT * FROM [dbo].[Document] WHERE FileName = @NewFileName) THEN CAST (1 AS BIT) ELSE CAST (0 AS BIT) )", con);
{
cmdName.Parameters.AddWithValue("@NewFileName", NewFileName);
cmdName.ExecuteNonQuery();
}
Any suggestions?
The whole code is to prevent user from renaming a file to one that already existed in the table. So, if there is a better way to do it, I'd appreciate the help.