سلام
من یک function زیر رو در sqlserver2005 نوشتم
ولی از داخل asp.net نمیتونم از مقدار برگشتی تابع استفاده کنم:
در خطی از ExecuteScalar استفاده کردم خطای زیر را مشاهده میکنم
Object reference not set to an instance of an object
و با trace کردن هم متوجه شدم مقداری که این تابع برمیگردونه null ست
من یک function زیر رو در sqlserver2005 نوشتم
کد:
use FoodChips
Go
alter Function CheckInsert_tblUser (@fName nvarchar(50),@fLoginName nvarchar(50)) returns int
AS
begin
declare @Id int,
@retVal int
select @Id=(select urId from tblUser
where urName=@fName
or urLoginName=@fLoginName)
if (@Id>0)
set @retval= 0
else
set @retval= 1
return @retVal
end
ولی از داخل asp.net نمیتونم از مقدار برگشتی تابع استفاده کنم:
کد:
public bool checkInsert()
{
SqlConnection SQLConn = FoodChips.MyClass.DBCls.WebFoodChipsConn();
SqlCommand sqlCmnd = new SqlCommand("CheckInsert_tblUser", SQLConn);
sqlCmnd.CommandType = CommandType.StoredProcedure;
sqlCmnd.Parameters.Add("@fName", SqlDbType.NVarChar, 50);
sqlCmnd.Parameters["@fName"].Value = fName;
sqlCmnd.Parameters.Add("@fLoginName", SqlDbType.NVarChar, 50);
sqlCmnd.Parameters["@fLoginName"].Value = fLoginName;
SQLConn.Open();
int retVal = int.Parse(sqlCmnd.ExecuteScalar().ToString());
SQLConn.Close();
if (retVal == 1)
return true;
return false;
}
در خطی از ExecuteScalar استفاده کردم خطای زیر را مشاهده میکنم
Object reference not set to an instance of an object
و با trace کردن هم متوجه شدم مقداری که این تابع برمیگردونه null ست