A
Assimalyst
hi,
I'm trying to get a count of duplicate entried in a sql server table.
I have a section of code that is throwing an error:
SqlCommand cmd = new SqlCommand ("proc_DuplicateSurgery", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@sgyName",
SqlDbType.VarChar,50,"strSurgeryName"));
cmd.Parameters.Add(new SqlParameter("@sgyPostcode",
SqlDbType.VarChar,10,"strPostcode"));
SqlParameter objReturnParam = cmd.Parameters.Add(new
SqlParameter("@Duplicates", SqlDbType.Int));
objReturnParam.Direction = ParameterDirection.ReturnValue;
//
// If duplicates occur change FK's to match and delete them
//
if ((int)objReturnParam.Value > 1)
{
.. . .
it appears to run through but when it trys to run the if
((int)objReturnParam.Value > 1) line it returns the error "Object
reference not set to an instance of an object".
Here's the stored procedure too:
CREATE PROCEDURE proc_DuplicateSurgery
(@sgyName varchar(50) = NULL,
@sgyPostcode varchar(10) = NULL,
@Duplicates int = 0
)
AS
SET @Duplicates =(SELECT COUNT(*) FROM tblReferringDoctorSurgery
WHERE sgyName = @sgyName AND sgyPostcode = @sgyPostcode)
RETURN @Duplicates
GO
Any ideas what the problem might be?
Thanks.
I'm trying to get a count of duplicate entried in a sql server table.
I have a section of code that is throwing an error:
SqlCommand cmd = new SqlCommand ("proc_DuplicateSurgery", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@sgyName",
SqlDbType.VarChar,50,"strSurgeryName"));
cmd.Parameters.Add(new SqlParameter("@sgyPostcode",
SqlDbType.VarChar,10,"strPostcode"));
SqlParameter objReturnParam = cmd.Parameters.Add(new
SqlParameter("@Duplicates", SqlDbType.Int));
objReturnParam.Direction = ParameterDirection.ReturnValue;
//
// If duplicates occur change FK's to match and delete them
//
if ((int)objReturnParam.Value > 1)
{
.. . .
it appears to run through but when it trys to run the if
((int)objReturnParam.Value > 1) line it returns the error "Object
reference not set to an instance of an object".
Here's the stored procedure too:
CREATE PROCEDURE proc_DuplicateSurgery
(@sgyName varchar(50) = NULL,
@sgyPostcode varchar(10) = NULL,
@Duplicates int = 0
)
AS
SET @Duplicates =(SELECT COUNT(*) FROM tblReferringDoctorSurgery
WHERE sgyName = @sgyName AND sgyPostcode = @sgyPostcode)
RETURN @Duplicates
GO
Any ideas what the problem might be?
Thanks.