Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlCon"].ToString());

            try
            {
                if (con.State == ConnectionState.Closed)
                    con.Open();
            }
            catch { }
            cmd = new SqlCommand("uspInsertRuleset", con);
            cmd.CommandType = CommandType.StoredProcedure;

            SqlParameter p1 = cmd.Parameters.Add("@RuleSetID", SqlDbType.Int);
            p1.Direction = ParameterDirection.Output;

            SqlParameter p2 = cmd.Parameters.Add("@RuleTypeID", SqlDbType.Int);
            p2.Direction = ParameterDirection.Output;

            SqlParameter p3 = cmd.Parameters.Add("@RuleID", SqlDbType.Int);
            p3.Direction = ParameterDirection.Output;

cmd.ExecuteNonQuery();
if (p1.Value == null)
{
    con.Close();
    return false;
}
Posted
Updated 21-Apr-15 23:29pm
v2

RuleId column requires a value. Here you are not passing it into the stored procedure.
The direction is an OUPUT parameter.

SqlParameter p3 = cmd.Parameters.Add("@RuleID", SqlDbType.Int);
p3.Direction = ParameterDirection.Output;
 
Share this answer
 
Check table defination Constaint can RuleId Allow Null Value Or Not
 
Share this answer
 
ALTER procedure [dbo].[uspInsertRuleset] @RuleSetID int out
,@RuleTypeID int out,
@RuleID int out,
@minRange nvarchar(20),
@maxRange nvarchar(20),
@invalidChars nvarchar(50),
@isMandatory bit,
@allowZeroAsValue bit,
@RuleSetName nvarchar(20),
@UserID int,
@RuleTypeName nvarchar(20),
@RuleName nvarchar(50)
as
begin


select @RuleTypeID=rtRuleTypeID from dbo.pltblRuleTypes where rtRuleTypeName=@RuleTypeName;

select @RuleID=rulesRuleID from dbo.tblRules where ruleAttribute=@RuleName and rulesRuleTypeID=@RuleTypeID;

select @RuleSetID=Max(rsetRuleSetID)+1 from dbo.tblUserRuleSet

IF @RuleSetID is null
set @RuleSetID=1;
ELSE
select @RuleSetID=Max(rsetRuleSetID)+1 from dbo.tblUserRuleSet


alter table [dbo].[linkRulesRuleSets] nocheck constraint all


INSERT INTO [dbo].[linkRulesRuleSets]
([RuleSetID]
,[RuleTypeID]
,[RuleID]
,[minRange]
,[maxRange]
,[invalidChars])
VALUES
(@RuleSetID,
@RuleTypeID,
@RuleID,
@minRange,
@maxRange,
@invalidChars)



alter table [dbo].[linkRulesRuleSets] check constraint all


end
this is my stored procedure and rule id is not null
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900