executescalar in c# code example
Example 1: mysql executeScalar only if successful
MySqlCommand cmd = new MySqlCommand(connection);
cmd.CommandText = sqlstring;
Object userNameObj = cmd.ExecuteScalar();
if (userNameObj != null)
string returnedName = userNameObj.ToString();
...
Example 2: executescalar in sql server
DECLARE @IsDuplicate BIT
IF EXISTS(SELECT * FROM dbo.ListData WHERE [description] = @description AND [dataTypeId] = @dataTypeId) -- Checking if duplicate name
SET @IsDuplicate = 1
ELSE
BEGIN
END