I want to check whether a logic name exists in the Logic table or not. my query and procedure are working correctly but in the C# code, it doesn't work correctly. it supposes to ExecuteSchalar() return 0 or 1 and then I check it and show a message box or something else. here is my code
string LogicNameCheck_Query = "exec searchLogicName '{0}'";
LogicNameCheck_Query = string.Format(LogicNameCheck_Query , txtLogicName);
SqlCommand sc = new SqlCommand();
sc.Connection = sqlConnection1;
sc.CommandText = LogicNameCheck_Query;
if (sqlConnection1.State != ConnectionState.Open)
{
sqlConnection1.Open();
}
int existLogicName = Convert.ToInt32(sc.ExecuteScalar());
MessageBox.Show(existLogicName +"");
if(existLogicName == 1)
{
MessageBox.Show("the name is exist");
return;
}
if (sqlConnection1.State != ConnectionState.Closed)
{
sqlConnection1.Close();
}
below is searchLogicName procedure code:
ALTER procedure [dbo].[searchLogicName]
@LogName varchar(50)
as
IF EXISTS (select * from Logic where LogicName = @LogName)
select 1 else select 0