ziduat
یک شنبه 23 تیر 1392, 13:05 عصر
سلام به همه
من یک stored procedure نوشتم که بر اساس یه شرط یا باید 1 یا -1 رو برگردونه. به صورت زیر:
ALTER PROCEDURE [dbo].[check]
AS
BEGIN
if exists(select personnelcode
from table1
where table1.personnelcode not in (select personnelcode
from table2))
return (-1)
else
return 1
END
توی ویژوال هم به این صورت نوشتم:
public static int operatequery(string storedprocedurename)
{
connection = new SqlConnection(connectionstring);
try
{
SqlCommand command = new SqlCommand(storedprocedurename, connection);
command.CommandTimeout = int.MaxValue;
command.CommandType = CommandType.StoredProcedure;
connection.Open();
object returnvalue = command.ExecuteScalar();
connection.Close();
return int.Parse("0" + returnvalue);
}
catch (Exception ex)
{
connection.Close();
return -1;
}
}
و بعد این تابع رو توی رویداد یک button فراخوانی کردم ولی مشکلی که داره اینه که return value توی تابع null هست و مقدار نمی گیره
ممنون میشم راهنمایی کنید.
من یک stored procedure نوشتم که بر اساس یه شرط یا باید 1 یا -1 رو برگردونه. به صورت زیر:
ALTER PROCEDURE [dbo].[check]
AS
BEGIN
if exists(select personnelcode
from table1
where table1.personnelcode not in (select personnelcode
from table2))
return (-1)
else
return 1
END
توی ویژوال هم به این صورت نوشتم:
public static int operatequery(string storedprocedurename)
{
connection = new SqlConnection(connectionstring);
try
{
SqlCommand command = new SqlCommand(storedprocedurename, connection);
command.CommandTimeout = int.MaxValue;
command.CommandType = CommandType.StoredProcedure;
connection.Open();
object returnvalue = command.ExecuteScalar();
connection.Close();
return int.Parse("0" + returnvalue);
}
catch (Exception ex)
{
connection.Close();
return -1;
}
}
و بعد این تابع رو توی رویداد یک button فراخوانی کردم ولی مشکلی که داره اینه که return value توی تابع null هست و مقدار نمی گیره
ممنون میشم راهنمایی کنید.