I'm not getting the right result with this store procedure











up vote
0
down vote

favorite












I use this store procedure to get the list of test created, but anytime i make a new entry(create a new test) the new entry is not showing on the list.



But i added 2 new columns to Test Table called StartDateTime and EndDateTime



USE [School-OnPremise]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[CMS_Test_GetList]
@SubjectId int,
@ProgramId int,
@ProgramLevelId int,
@AcademicTerm int,
@AcademicSession int,
@AddedBy int,
@EntityStatus int = null

AS
BEGIN
SET NOCOUNT ON;
select i.*,
(select Count(*) from TestQuestion where TestId = i.Id) As QuestionNumber,
(select Count(*) from StudentTests where TestId = i.Id and score is not
null) AS ResultsCount
from Test AS i
where i.ClassId =COALESCE(@ProgramId,i.ClassId)
and i.SubjectId = COALESCE(@SubjectId,i.SubjectId)
and i.Session = COALESCE(@AcademicSession,i.Session)
and i.AcademicTerm = COALESCE(@AcademicTerm,i.AcademicTerm)
and i.AddedBy = COALESCE(@AddedBy,i.AddedBy)
and i.EntityStatus = COALESCE(@EntityStatus,EntityStatus)
order by i.AddedOn desc
END


GO


this the table when i execute the stored procedure passing the argument needed i am supposed to get the entries that fall in the category of the arguments i passed.click sql table to see the image below



sql table



When i tried to execute the store procedure this is what i get



USE [School-OnPremise]
GO

DECLARE @return_value int

EXEC @return_value = [dbo].[CMS_Test_GetList]
@SubjectId = 3142,
@ProgramId = 2045,
@ProgramLevelId = 0,
@AcademicTerm = 1,
@AcademicSession = 2018,
@AddedBy = 3,
@EntityStatus = null

SELECT 'Return Value' = @return_value

GO


this is the ouput i get



ouput



ouput cont.










share|improve this question




















  • 1




    You do not provide sufficient information for us to help you. Please take a look at stackoverflow.com/help/mcve
    – Squirrel
    Nov 22 at 9:38






  • 1




    At a total guess (using my crystal ball for the day): You state "i added 2 new columns to Test Table " yet you use select i.*,. Unless you have updated the definition of the trigger, the columns returned by * won't update. *. In a compiled object, will only return columns at the time it was compiled; and can have some odd behaviour after an object is changed. You should declare all your columns, and amend the trigger appropriately with the new columns.
    – Larnu
    Nov 22 at 9:41












  • @Larnu thanks for your reply but i have tried that when executing the stored procedure using sql management studio passing the arguments needed the columns i added usually double up(having 2 columns of StartDateTime and EndDateTime) in the output area
    – Timothy
    Nov 22 at 9:57












  • Can you post the table definition for table "Test"? And update with your current code as it must have been changed to "double up" your output columns... I can't see any way that is possible with the code initially posted. The only way I can think of the 2 new columns "doubling up" is by adding them to the select list along with *.
    – Allumearz
    Nov 22 at 10:04










  • @Allumearz yeah you are right i was including the columns in the select list, but i'm not still getting the result i want. Hold on a sec i will post something now
    – Timothy
    Nov 22 at 10:15















up vote
0
down vote

favorite












I use this store procedure to get the list of test created, but anytime i make a new entry(create a new test) the new entry is not showing on the list.



But i added 2 new columns to Test Table called StartDateTime and EndDateTime



USE [School-OnPremise]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[CMS_Test_GetList]
@SubjectId int,
@ProgramId int,
@ProgramLevelId int,
@AcademicTerm int,
@AcademicSession int,
@AddedBy int,
@EntityStatus int = null

AS
BEGIN
SET NOCOUNT ON;
select i.*,
(select Count(*) from TestQuestion where TestId = i.Id) As QuestionNumber,
(select Count(*) from StudentTests where TestId = i.Id and score is not
null) AS ResultsCount
from Test AS i
where i.ClassId =COALESCE(@ProgramId,i.ClassId)
and i.SubjectId = COALESCE(@SubjectId,i.SubjectId)
and i.Session = COALESCE(@AcademicSession,i.Session)
and i.AcademicTerm = COALESCE(@AcademicTerm,i.AcademicTerm)
and i.AddedBy = COALESCE(@AddedBy,i.AddedBy)
and i.EntityStatus = COALESCE(@EntityStatus,EntityStatus)
order by i.AddedOn desc
END


GO


this the table when i execute the stored procedure passing the argument needed i am supposed to get the entries that fall in the category of the arguments i passed.click sql table to see the image below



sql table



When i tried to execute the store procedure this is what i get



USE [School-OnPremise]
GO

DECLARE @return_value int

EXEC @return_value = [dbo].[CMS_Test_GetList]
@SubjectId = 3142,
@ProgramId = 2045,
@ProgramLevelId = 0,
@AcademicTerm = 1,
@AcademicSession = 2018,
@AddedBy = 3,
@EntityStatus = null

SELECT 'Return Value' = @return_value

GO


this is the ouput i get



ouput



ouput cont.










share|improve this question




















  • 1




    You do not provide sufficient information for us to help you. Please take a look at stackoverflow.com/help/mcve
    – Squirrel
    Nov 22 at 9:38






  • 1




    At a total guess (using my crystal ball for the day): You state "i added 2 new columns to Test Table " yet you use select i.*,. Unless you have updated the definition of the trigger, the columns returned by * won't update. *. In a compiled object, will only return columns at the time it was compiled; and can have some odd behaviour after an object is changed. You should declare all your columns, and amend the trigger appropriately with the new columns.
    – Larnu
    Nov 22 at 9:41












  • @Larnu thanks for your reply but i have tried that when executing the stored procedure using sql management studio passing the arguments needed the columns i added usually double up(having 2 columns of StartDateTime and EndDateTime) in the output area
    – Timothy
    Nov 22 at 9:57












  • Can you post the table definition for table "Test"? And update with your current code as it must have been changed to "double up" your output columns... I can't see any way that is possible with the code initially posted. The only way I can think of the 2 new columns "doubling up" is by adding them to the select list along with *.
    – Allumearz
    Nov 22 at 10:04










  • @Allumearz yeah you are right i was including the columns in the select list, but i'm not still getting the result i want. Hold on a sec i will post something now
    – Timothy
    Nov 22 at 10:15













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I use this store procedure to get the list of test created, but anytime i make a new entry(create a new test) the new entry is not showing on the list.



But i added 2 new columns to Test Table called StartDateTime and EndDateTime



USE [School-OnPremise]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[CMS_Test_GetList]
@SubjectId int,
@ProgramId int,
@ProgramLevelId int,
@AcademicTerm int,
@AcademicSession int,
@AddedBy int,
@EntityStatus int = null

AS
BEGIN
SET NOCOUNT ON;
select i.*,
(select Count(*) from TestQuestion where TestId = i.Id) As QuestionNumber,
(select Count(*) from StudentTests where TestId = i.Id and score is not
null) AS ResultsCount
from Test AS i
where i.ClassId =COALESCE(@ProgramId,i.ClassId)
and i.SubjectId = COALESCE(@SubjectId,i.SubjectId)
and i.Session = COALESCE(@AcademicSession,i.Session)
and i.AcademicTerm = COALESCE(@AcademicTerm,i.AcademicTerm)
and i.AddedBy = COALESCE(@AddedBy,i.AddedBy)
and i.EntityStatus = COALESCE(@EntityStatus,EntityStatus)
order by i.AddedOn desc
END


GO


this the table when i execute the stored procedure passing the argument needed i am supposed to get the entries that fall in the category of the arguments i passed.click sql table to see the image below



sql table



When i tried to execute the store procedure this is what i get



USE [School-OnPremise]
GO

DECLARE @return_value int

EXEC @return_value = [dbo].[CMS_Test_GetList]
@SubjectId = 3142,
@ProgramId = 2045,
@ProgramLevelId = 0,
@AcademicTerm = 1,
@AcademicSession = 2018,
@AddedBy = 3,
@EntityStatus = null

SELECT 'Return Value' = @return_value

GO


this is the ouput i get



ouput



ouput cont.










share|improve this question















I use this store procedure to get the list of test created, but anytime i make a new entry(create a new test) the new entry is not showing on the list.



But i added 2 new columns to Test Table called StartDateTime and EndDateTime



USE [School-OnPremise]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[CMS_Test_GetList]
@SubjectId int,
@ProgramId int,
@ProgramLevelId int,
@AcademicTerm int,
@AcademicSession int,
@AddedBy int,
@EntityStatus int = null

AS
BEGIN
SET NOCOUNT ON;
select i.*,
(select Count(*) from TestQuestion where TestId = i.Id) As QuestionNumber,
(select Count(*) from StudentTests where TestId = i.Id and score is not
null) AS ResultsCount
from Test AS i
where i.ClassId =COALESCE(@ProgramId,i.ClassId)
and i.SubjectId = COALESCE(@SubjectId,i.SubjectId)
and i.Session = COALESCE(@AcademicSession,i.Session)
and i.AcademicTerm = COALESCE(@AcademicTerm,i.AcademicTerm)
and i.AddedBy = COALESCE(@AddedBy,i.AddedBy)
and i.EntityStatus = COALESCE(@EntityStatus,EntityStatus)
order by i.AddedOn desc
END


GO


this the table when i execute the stored procedure passing the argument needed i am supposed to get the entries that fall in the category of the arguments i passed.click sql table to see the image below



sql table



When i tried to execute the store procedure this is what i get



USE [School-OnPremise]
GO

DECLARE @return_value int

EXEC @return_value = [dbo].[CMS_Test_GetList]
@SubjectId = 3142,
@ProgramId = 2045,
@ProgramLevelId = 0,
@AcademicTerm = 1,
@AcademicSession = 2018,
@AddedBy = 3,
@EntityStatus = null

SELECT 'Return Value' = @return_value

GO


this is the ouput i get



ouput



ouput cont.







c# sql-server






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 21:20







user3559349

















asked Nov 22 at 9:37









Timothy

34




34








  • 1




    You do not provide sufficient information for us to help you. Please take a look at stackoverflow.com/help/mcve
    – Squirrel
    Nov 22 at 9:38






  • 1




    At a total guess (using my crystal ball for the day): You state "i added 2 new columns to Test Table " yet you use select i.*,. Unless you have updated the definition of the trigger, the columns returned by * won't update. *. In a compiled object, will only return columns at the time it was compiled; and can have some odd behaviour after an object is changed. You should declare all your columns, and amend the trigger appropriately with the new columns.
    – Larnu
    Nov 22 at 9:41












  • @Larnu thanks for your reply but i have tried that when executing the stored procedure using sql management studio passing the arguments needed the columns i added usually double up(having 2 columns of StartDateTime and EndDateTime) in the output area
    – Timothy
    Nov 22 at 9:57












  • Can you post the table definition for table "Test"? And update with your current code as it must have been changed to "double up" your output columns... I can't see any way that is possible with the code initially posted. The only way I can think of the 2 new columns "doubling up" is by adding them to the select list along with *.
    – Allumearz
    Nov 22 at 10:04










  • @Allumearz yeah you are right i was including the columns in the select list, but i'm not still getting the result i want. Hold on a sec i will post something now
    – Timothy
    Nov 22 at 10:15














  • 1




    You do not provide sufficient information for us to help you. Please take a look at stackoverflow.com/help/mcve
    – Squirrel
    Nov 22 at 9:38






  • 1




    At a total guess (using my crystal ball for the day): You state "i added 2 new columns to Test Table " yet you use select i.*,. Unless you have updated the definition of the trigger, the columns returned by * won't update. *. In a compiled object, will only return columns at the time it was compiled; and can have some odd behaviour after an object is changed. You should declare all your columns, and amend the trigger appropriately with the new columns.
    – Larnu
    Nov 22 at 9:41












  • @Larnu thanks for your reply but i have tried that when executing the stored procedure using sql management studio passing the arguments needed the columns i added usually double up(having 2 columns of StartDateTime and EndDateTime) in the output area
    – Timothy
    Nov 22 at 9:57












  • Can you post the table definition for table "Test"? And update with your current code as it must have been changed to "double up" your output columns... I can't see any way that is possible with the code initially posted. The only way I can think of the 2 new columns "doubling up" is by adding them to the select list along with *.
    – Allumearz
    Nov 22 at 10:04










  • @Allumearz yeah you are right i was including the columns in the select list, but i'm not still getting the result i want. Hold on a sec i will post something now
    – Timothy
    Nov 22 at 10:15








1




1




You do not provide sufficient information for us to help you. Please take a look at stackoverflow.com/help/mcve
– Squirrel
Nov 22 at 9:38




You do not provide sufficient information for us to help you. Please take a look at stackoverflow.com/help/mcve
– Squirrel
Nov 22 at 9:38




1




1




At a total guess (using my crystal ball for the day): You state "i added 2 new columns to Test Table " yet you use select i.*,. Unless you have updated the definition of the trigger, the columns returned by * won't update. *. In a compiled object, will only return columns at the time it was compiled; and can have some odd behaviour after an object is changed. You should declare all your columns, and amend the trigger appropriately with the new columns.
– Larnu
Nov 22 at 9:41






At a total guess (using my crystal ball for the day): You state "i added 2 new columns to Test Table " yet you use select i.*,. Unless you have updated the definition of the trigger, the columns returned by * won't update. *. In a compiled object, will only return columns at the time it was compiled; and can have some odd behaviour after an object is changed. You should declare all your columns, and amend the trigger appropriately with the new columns.
– Larnu
Nov 22 at 9:41














@Larnu thanks for your reply but i have tried that when executing the stored procedure using sql management studio passing the arguments needed the columns i added usually double up(having 2 columns of StartDateTime and EndDateTime) in the output area
– Timothy
Nov 22 at 9:57






@Larnu thanks for your reply but i have tried that when executing the stored procedure using sql management studio passing the arguments needed the columns i added usually double up(having 2 columns of StartDateTime and EndDateTime) in the output area
– Timothy
Nov 22 at 9:57














Can you post the table definition for table "Test"? And update with your current code as it must have been changed to "double up" your output columns... I can't see any way that is possible with the code initially posted. The only way I can think of the 2 new columns "doubling up" is by adding them to the select list along with *.
– Allumearz
Nov 22 at 10:04




Can you post the table definition for table "Test"? And update with your current code as it must have been changed to "double up" your output columns... I can't see any way that is possible with the code initially posted. The only way I can think of the 2 new columns "doubling up" is by adding them to the select list along with *.
– Allumearz
Nov 22 at 10:04












@Allumearz yeah you are right i was including the columns in the select list, but i'm not still getting the result i want. Hold on a sec i will post something now
– Timothy
Nov 22 at 10:15




@Allumearz yeah you are right i was including the columns in the select list, but i'm not still getting the result i want. Hold on a sec i will post something now
– Timothy
Nov 22 at 10:15












2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










Ah, your final condition is testing i.EntityStatus = NULL - this will not work - if a column value = null then it will only satisfy the IS NULL operator.



and (@EntityStatus IS NULL OR (@EntityStatus IS NOT NULL AND i.EntityStatus = @EntityStatus))





share|improve this answer





















  • I am assuming here that EntityStatus values in the database are currently NULL - I cannot see that column value in your screenshot... Please correct me if the values are something other than NULL.
    – Allumearz
    Nov 22 at 11:04










  • yes the entity status is null, thanks a lot for your time, I've seen the problem not the stored procedure the problem from my code. At the point of creating a test, I was not saving the value of the entitystatus. it is when editing a test the value of the enititystatus will be saved because it is was only added in the form for the edit page
    – Timothy
    Nov 22 at 12:08










  • @Timothy: not even a +1 or accepted answer?! I answered your question as to why your stored procedure was not returning the expected result. If you had replaced the condition in the SP, it would have returned all the rows you expected, including the NULL values in EntityStatus. If the EntityStatus should never contain NULL, then it should be declared as a NOT NULL column - then your program would have failed when trying to insert NULL - highlighting your initial problem and not a red herring!
    – Allumearz
    Nov 22 at 12:27










  • i'm sorry about the +1 thing i don't really post question on stack overflow so i didn't know i was suppose to do that. Anyways i just accepted your anwer but i cannot change the 0 to +1 i don't know why. Thanks once again
    – Timothy
    Nov 22 at 12:44




















up vote
0
down vote













the problem is not the test procedure, it from the code below there is nothing saving the enitystatus' value



    public bool insert_New_Test(string TestName, int Duration, int SessionYear, int ClassId, int SubjectId, bool Status, int AddedBy,
int ProgramLevelId, int AcademicTerm, int questionSetUpType, out int id, DateTime startDateTime, DateTime endDateTime, int? testType)
{
bool functionReturnValue = false;
id = 0;
try
{
using (SqlConnection con = new SqlConnection(conn))
{
con.Open();
SqlCommand oComm = new SqlCommand();
using (oComm)
{
oComm.Connection = con;
oComm.CommandType = CommandType.StoredProcedure;
oComm.CommandText = "CMS_Test_Insert";

oComm.Parameters.Add(new SqlParameter("@Title", SqlDbType.NVarChar));
oComm.Parameters["@Title"].Value = TestName;

oComm.Parameters.Add(new SqlParameter("@SubjectId", SqlDbType.Int));
oComm.Parameters["@SubjectId"].Value = SubjectId;

oComm.Parameters.Add(new SqlParameter("@ClassId", SqlDbType.Int));
oComm.Parameters["@ClassId"].Value = ClassId;

oComm.Parameters.Add(new SqlParameter("@Session", SqlDbType.Int));
oComm.Parameters["@Session"].Value = SessionYear;

oComm.Parameters.Add(new SqlParameter("@ProgramLevelId", SqlDbType.Int));
oComm.Parameters["@ProgramLevelId"].Value = ProgramLevelId;

oComm.Parameters.Add(new SqlParameter("@AcademicTerm", SqlDbType.Int));
oComm.Parameters["@AcademicTerm"].Value = AcademicTerm;

oComm.Parameters.Add(new SqlParameter("@Duration", SqlDbType.Int));
oComm.Parameters["@Duration"].Value = Duration;

oComm.Parameters.Add(new SqlParameter("@Status", SqlDbType.Bit));
oComm.Parameters["@Status"].Value = Status;

oComm.Parameters.Add(new SqlParameter("@AddedBy", SqlDbType.Int));
oComm.Parameters["@AddedBy"].Value = AddedBy;


oComm.Parameters.Add(new SqlParameter("@QuestionSetupType", SqlDbType.Int));
oComm.Parameters["@QuestionSetupType"].Value = questionSetUpType;

if (startDateTime > DateTime.MinValue)
{
oComm.Parameters.Add(new SqlParameter("@StartDateTime", SqlDbType.DateTime));
oComm.Parameters["@StartDateTime"].Value = startDateTime;
}
if (endDateTime > DateTime.MinValue)
{
oComm.Parameters.Add(new SqlParameter("@EndDateTime", SqlDbType.DateTime));
oComm.Parameters["@EndDateTime"].Value = endDateTime;
}

oComm.Parameters.Add(new SqlParameter("@TestType", SqlDbType.Int));
oComm.Parameters["@TestType"].Value = testType;

oComm.Parameters.Add(new SqlParameter("@Success", SqlDbType.Bit));
oComm.Parameters["@Success"].Direction = ParameterDirection.Output;

oComm.Parameters.Add(new SqlParameter("@TestId", SqlDbType.Int));
oComm.Parameters["@TestId"].Direction = ParameterDirection.Output;
oComm.ExecuteNonQuery();
functionReturnValue = Convert.ToBoolean(oComm.Parameters["@Success"].Value);
id = Convert.ToInt32(oComm.Parameters["@TestId"].Value);

}
con.Close();
}

}
catch (SqlException ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
functionReturnValue = false;
}
return functionReturnValue;

}


so when it try to get the value for the entitystatus the value is null



public List<TestViewModel> get_List_Of_Test(int SubjectId, int ProgramLevelId, int AcademicTerm, int AcademicSession,
int ProgramId, int status)
{
List<TestViewModel> sList = new List<TestViewModel>();
try
{
using (SqlConnection con = new SqlConnection(conn))
{
con.Open();
SqlCommand oComm = new SqlCommand();
using (oComm)
{
oComm.Connection = con;
oComm.CommandType = CommandType.StoredProcedure;
oComm.CommandText = "CMS_Test_GetList";

oComm.Parameters.Add(new SqlParameter("@SubjectId", SqlDbType.Int));
oComm.Parameters["@SubjectId"].Value = SubjectId == 0 ? System.Data.SqlTypes.SqlInt32.Null : SubjectId;

oComm.Parameters.Add(new SqlParameter("@ProgramId", SqlDbType.Int));
oComm.Parameters["@ProgramId"].Value = ProgramId == 0 ? System.Data.SqlTypes.SqlInt32.Null : ProgramId;

oComm.Parameters.Add(new SqlParameter("@ProgramLevelId", SqlDbType.Int));
oComm.Parameters["@ProgramLevelId"].Value = ProgramLevelId == 0 ? System.Data.SqlTypes.SqlInt32.Null : ProgramLevelId;

oComm.Parameters.Add(new SqlParameter("@AcademicSession", SqlDbType.Int));
oComm.Parameters["@AcademicSession"].Value = AcademicSession == 0 ? System.Data.SqlTypes.SqlInt32.Null : AcademicSession;

oComm.Parameters.Add(new SqlParameter("@AcademicTerm", SqlDbType.Int));
oComm.Parameters["@AcademicTerm"].Value = AcademicTerm == 0 ? System.Data.SqlTypes.SqlInt32.Null : AcademicTerm;

oComm.Parameters.Add(new SqlParameter("@AddedBy", SqlDbType.Int));
oComm.Parameters["@AddedBy"].Value = MembershipHelper.GetActiveUser().Teacher.IsAdmin ? System.Data.SqlTypes.SqlInt32.Null : MembershipHelper.GetActiveUserId;

oComm.Parameters.Add(new SqlParameter("@EntityStatus", SqlDbType.Int));
oComm.Parameters["@EntityStatus"].Value = status;

SqlDataReader rdr = oComm.ExecuteReader();
if (rdr.HasRows)
{
int _sn = 0;
while (rdr.Read())
{
int publicStatus = _rdrHelper.getOrdinalInt32Value(rdr, "EntityStatus");
_sn++;
TestViewModel qList = new TestViewModel();
qList.ProgramLevelId = _rdrHelper.getOrdinalInt32Value(rdr, "ProgramLevel");
qList.ProgramLevelText = Extensions.ListEnums.GetProgramLevel().Skip(qList.ProgramLevelId - 1).First().Text;
qList.AcademicTermId = _rdrHelper.getOrdinalInt32Value(rdr, "AcademicTerm");
qList.AcademicTermText = Extensions.ListEnums.GetTermChoice().Skip(qList.AcademicTermId - 1).First().Text;
qList.TestTitle = _rdrHelper.GetOrdinalStringValue(rdr, "Title");
qList.ClassId = _rdrHelper.getOrdinalInt32Value(rdr, "ClassId");
qList.ClassName = _rdrHelper.GetOrdinalStringValue(rdr, "ClassName");
qList.SubjectName = _rdrHelper.GetOrdinalStringValue(rdr, "SubjectName");
qList.SessionId = _rdrHelper.getOrdinalInt32Value(rdr, "Session");
qList.TestId = _rdrHelper.getOrdinalInt32Value(rdr, "Id");
qList.Duration = _rdrHelper.getOrdinalInt32Value(rdr, "Duration");
qList.Status = _rdrHelper.getOrdinalBooleanValue(rdr, "Status");
qList.QuestionCount = _rdrHelper.getOrdinalInt32Value(rdr, "QuestionNumber");
qList.TestSn = _sn;
qList.ResultExists = _rdrHelper.getOrdinalInt32Value(rdr, "ResultsCount") > 0;
qList.AddedBy = _rdrHelper.getOrdinalInt32Value(rdr, "AddedBy");
qList.Test.StartDateTime = _rdrHelper.getNullableOrdinalDatetimeValue(rdr, "StartDateTime");
qList.Test.EndDateTime = _rdrHelper.getNullableOrdinalDatetimeValue(rdr, "EndDateTime");
qList.Test.EntityStatus = publicStatus;
sList.Add(qList);
}
}
con.Close();
}

}
}


one my create page there is no field to pass the value for the entitystatus



create test page



but for the edit page there is a field to pass value into the entitystatus



edit page



the publish status is the field that gives the entity status value. The thing is after creating the test i'm redirected to the edit page to click the save button so that all entries will be saved into the databas3 but i did not click the save button i just went back to the index page which shows the list of tests.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427846%2fim-not-getting-the-right-result-with-this-store-procedure%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    Ah, your final condition is testing i.EntityStatus = NULL - this will not work - if a column value = null then it will only satisfy the IS NULL operator.



    and (@EntityStatus IS NULL OR (@EntityStatus IS NOT NULL AND i.EntityStatus = @EntityStatus))





    share|improve this answer





















    • I am assuming here that EntityStatus values in the database are currently NULL - I cannot see that column value in your screenshot... Please correct me if the values are something other than NULL.
      – Allumearz
      Nov 22 at 11:04










    • yes the entity status is null, thanks a lot for your time, I've seen the problem not the stored procedure the problem from my code. At the point of creating a test, I was not saving the value of the entitystatus. it is when editing a test the value of the enititystatus will be saved because it is was only added in the form for the edit page
      – Timothy
      Nov 22 at 12:08










    • @Timothy: not even a +1 or accepted answer?! I answered your question as to why your stored procedure was not returning the expected result. If you had replaced the condition in the SP, it would have returned all the rows you expected, including the NULL values in EntityStatus. If the EntityStatus should never contain NULL, then it should be declared as a NOT NULL column - then your program would have failed when trying to insert NULL - highlighting your initial problem and not a red herring!
      – Allumearz
      Nov 22 at 12:27










    • i'm sorry about the +1 thing i don't really post question on stack overflow so i didn't know i was suppose to do that. Anyways i just accepted your anwer but i cannot change the 0 to +1 i don't know why. Thanks once again
      – Timothy
      Nov 22 at 12:44

















    up vote
    0
    down vote



    accepted










    Ah, your final condition is testing i.EntityStatus = NULL - this will not work - if a column value = null then it will only satisfy the IS NULL operator.



    and (@EntityStatus IS NULL OR (@EntityStatus IS NOT NULL AND i.EntityStatus = @EntityStatus))





    share|improve this answer





















    • I am assuming here that EntityStatus values in the database are currently NULL - I cannot see that column value in your screenshot... Please correct me if the values are something other than NULL.
      – Allumearz
      Nov 22 at 11:04










    • yes the entity status is null, thanks a lot for your time, I've seen the problem not the stored procedure the problem from my code. At the point of creating a test, I was not saving the value of the entitystatus. it is when editing a test the value of the enititystatus will be saved because it is was only added in the form for the edit page
      – Timothy
      Nov 22 at 12:08










    • @Timothy: not even a +1 or accepted answer?! I answered your question as to why your stored procedure was not returning the expected result. If you had replaced the condition in the SP, it would have returned all the rows you expected, including the NULL values in EntityStatus. If the EntityStatus should never contain NULL, then it should be declared as a NOT NULL column - then your program would have failed when trying to insert NULL - highlighting your initial problem and not a red herring!
      – Allumearz
      Nov 22 at 12:27










    • i'm sorry about the +1 thing i don't really post question on stack overflow so i didn't know i was suppose to do that. Anyways i just accepted your anwer but i cannot change the 0 to +1 i don't know why. Thanks once again
      – Timothy
      Nov 22 at 12:44















    up vote
    0
    down vote



    accepted







    up vote
    0
    down vote



    accepted






    Ah, your final condition is testing i.EntityStatus = NULL - this will not work - if a column value = null then it will only satisfy the IS NULL operator.



    and (@EntityStatus IS NULL OR (@EntityStatus IS NOT NULL AND i.EntityStatus = @EntityStatus))





    share|improve this answer












    Ah, your final condition is testing i.EntityStatus = NULL - this will not work - if a column value = null then it will only satisfy the IS NULL operator.



    and (@EntityStatus IS NULL OR (@EntityStatus IS NOT NULL AND i.EntityStatus = @EntityStatus))






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 22 at 11:00









    Allumearz

    1896




    1896












    • I am assuming here that EntityStatus values in the database are currently NULL - I cannot see that column value in your screenshot... Please correct me if the values are something other than NULL.
      – Allumearz
      Nov 22 at 11:04










    • yes the entity status is null, thanks a lot for your time, I've seen the problem not the stored procedure the problem from my code. At the point of creating a test, I was not saving the value of the entitystatus. it is when editing a test the value of the enititystatus will be saved because it is was only added in the form for the edit page
      – Timothy
      Nov 22 at 12:08










    • @Timothy: not even a +1 or accepted answer?! I answered your question as to why your stored procedure was not returning the expected result. If you had replaced the condition in the SP, it would have returned all the rows you expected, including the NULL values in EntityStatus. If the EntityStatus should never contain NULL, then it should be declared as a NOT NULL column - then your program would have failed when trying to insert NULL - highlighting your initial problem and not a red herring!
      – Allumearz
      Nov 22 at 12:27










    • i'm sorry about the +1 thing i don't really post question on stack overflow so i didn't know i was suppose to do that. Anyways i just accepted your anwer but i cannot change the 0 to +1 i don't know why. Thanks once again
      – Timothy
      Nov 22 at 12:44




















    • I am assuming here that EntityStatus values in the database are currently NULL - I cannot see that column value in your screenshot... Please correct me if the values are something other than NULL.
      – Allumearz
      Nov 22 at 11:04










    • yes the entity status is null, thanks a lot for your time, I've seen the problem not the stored procedure the problem from my code. At the point of creating a test, I was not saving the value of the entitystatus. it is when editing a test the value of the enititystatus will be saved because it is was only added in the form for the edit page
      – Timothy
      Nov 22 at 12:08










    • @Timothy: not even a +1 or accepted answer?! I answered your question as to why your stored procedure was not returning the expected result. If you had replaced the condition in the SP, it would have returned all the rows you expected, including the NULL values in EntityStatus. If the EntityStatus should never contain NULL, then it should be declared as a NOT NULL column - then your program would have failed when trying to insert NULL - highlighting your initial problem and not a red herring!
      – Allumearz
      Nov 22 at 12:27










    • i'm sorry about the +1 thing i don't really post question on stack overflow so i didn't know i was suppose to do that. Anyways i just accepted your anwer but i cannot change the 0 to +1 i don't know why. Thanks once again
      – Timothy
      Nov 22 at 12:44


















    I am assuming here that EntityStatus values in the database are currently NULL - I cannot see that column value in your screenshot... Please correct me if the values are something other than NULL.
    – Allumearz
    Nov 22 at 11:04




    I am assuming here that EntityStatus values in the database are currently NULL - I cannot see that column value in your screenshot... Please correct me if the values are something other than NULL.
    – Allumearz
    Nov 22 at 11:04












    yes the entity status is null, thanks a lot for your time, I've seen the problem not the stored procedure the problem from my code. At the point of creating a test, I was not saving the value of the entitystatus. it is when editing a test the value of the enititystatus will be saved because it is was only added in the form for the edit page
    – Timothy
    Nov 22 at 12:08




    yes the entity status is null, thanks a lot for your time, I've seen the problem not the stored procedure the problem from my code. At the point of creating a test, I was not saving the value of the entitystatus. it is when editing a test the value of the enititystatus will be saved because it is was only added in the form for the edit page
    – Timothy
    Nov 22 at 12:08












    @Timothy: not even a +1 or accepted answer?! I answered your question as to why your stored procedure was not returning the expected result. If you had replaced the condition in the SP, it would have returned all the rows you expected, including the NULL values in EntityStatus. If the EntityStatus should never contain NULL, then it should be declared as a NOT NULL column - then your program would have failed when trying to insert NULL - highlighting your initial problem and not a red herring!
    – Allumearz
    Nov 22 at 12:27




    @Timothy: not even a +1 or accepted answer?! I answered your question as to why your stored procedure was not returning the expected result. If you had replaced the condition in the SP, it would have returned all the rows you expected, including the NULL values in EntityStatus. If the EntityStatus should never contain NULL, then it should be declared as a NOT NULL column - then your program would have failed when trying to insert NULL - highlighting your initial problem and not a red herring!
    – Allumearz
    Nov 22 at 12:27












    i'm sorry about the +1 thing i don't really post question on stack overflow so i didn't know i was suppose to do that. Anyways i just accepted your anwer but i cannot change the 0 to +1 i don't know why. Thanks once again
    – Timothy
    Nov 22 at 12:44






    i'm sorry about the +1 thing i don't really post question on stack overflow so i didn't know i was suppose to do that. Anyways i just accepted your anwer but i cannot change the 0 to +1 i don't know why. Thanks once again
    – Timothy
    Nov 22 at 12:44














    up vote
    0
    down vote













    the problem is not the test procedure, it from the code below there is nothing saving the enitystatus' value



        public bool insert_New_Test(string TestName, int Duration, int SessionYear, int ClassId, int SubjectId, bool Status, int AddedBy,
    int ProgramLevelId, int AcademicTerm, int questionSetUpType, out int id, DateTime startDateTime, DateTime endDateTime, int? testType)
    {
    bool functionReturnValue = false;
    id = 0;
    try
    {
    using (SqlConnection con = new SqlConnection(conn))
    {
    con.Open();
    SqlCommand oComm = new SqlCommand();
    using (oComm)
    {
    oComm.Connection = con;
    oComm.CommandType = CommandType.StoredProcedure;
    oComm.CommandText = "CMS_Test_Insert";

    oComm.Parameters.Add(new SqlParameter("@Title", SqlDbType.NVarChar));
    oComm.Parameters["@Title"].Value = TestName;

    oComm.Parameters.Add(new SqlParameter("@SubjectId", SqlDbType.Int));
    oComm.Parameters["@SubjectId"].Value = SubjectId;

    oComm.Parameters.Add(new SqlParameter("@ClassId", SqlDbType.Int));
    oComm.Parameters["@ClassId"].Value = ClassId;

    oComm.Parameters.Add(new SqlParameter("@Session", SqlDbType.Int));
    oComm.Parameters["@Session"].Value = SessionYear;

    oComm.Parameters.Add(new SqlParameter("@ProgramLevelId", SqlDbType.Int));
    oComm.Parameters["@ProgramLevelId"].Value = ProgramLevelId;

    oComm.Parameters.Add(new SqlParameter("@AcademicTerm", SqlDbType.Int));
    oComm.Parameters["@AcademicTerm"].Value = AcademicTerm;

    oComm.Parameters.Add(new SqlParameter("@Duration", SqlDbType.Int));
    oComm.Parameters["@Duration"].Value = Duration;

    oComm.Parameters.Add(new SqlParameter("@Status", SqlDbType.Bit));
    oComm.Parameters["@Status"].Value = Status;

    oComm.Parameters.Add(new SqlParameter("@AddedBy", SqlDbType.Int));
    oComm.Parameters["@AddedBy"].Value = AddedBy;


    oComm.Parameters.Add(new SqlParameter("@QuestionSetupType", SqlDbType.Int));
    oComm.Parameters["@QuestionSetupType"].Value = questionSetUpType;

    if (startDateTime > DateTime.MinValue)
    {
    oComm.Parameters.Add(new SqlParameter("@StartDateTime", SqlDbType.DateTime));
    oComm.Parameters["@StartDateTime"].Value = startDateTime;
    }
    if (endDateTime > DateTime.MinValue)
    {
    oComm.Parameters.Add(new SqlParameter("@EndDateTime", SqlDbType.DateTime));
    oComm.Parameters["@EndDateTime"].Value = endDateTime;
    }

    oComm.Parameters.Add(new SqlParameter("@TestType", SqlDbType.Int));
    oComm.Parameters["@TestType"].Value = testType;

    oComm.Parameters.Add(new SqlParameter("@Success", SqlDbType.Bit));
    oComm.Parameters["@Success"].Direction = ParameterDirection.Output;

    oComm.Parameters.Add(new SqlParameter("@TestId", SqlDbType.Int));
    oComm.Parameters["@TestId"].Direction = ParameterDirection.Output;
    oComm.ExecuteNonQuery();
    functionReturnValue = Convert.ToBoolean(oComm.Parameters["@Success"].Value);
    id = Convert.ToInt32(oComm.Parameters["@TestId"].Value);

    }
    con.Close();
    }

    }
    catch (SqlException ex)
    {
    Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
    functionReturnValue = false;
    }
    return functionReturnValue;

    }


    so when it try to get the value for the entitystatus the value is null



    public List<TestViewModel> get_List_Of_Test(int SubjectId, int ProgramLevelId, int AcademicTerm, int AcademicSession,
    int ProgramId, int status)
    {
    List<TestViewModel> sList = new List<TestViewModel>();
    try
    {
    using (SqlConnection con = new SqlConnection(conn))
    {
    con.Open();
    SqlCommand oComm = new SqlCommand();
    using (oComm)
    {
    oComm.Connection = con;
    oComm.CommandType = CommandType.StoredProcedure;
    oComm.CommandText = "CMS_Test_GetList";

    oComm.Parameters.Add(new SqlParameter("@SubjectId", SqlDbType.Int));
    oComm.Parameters["@SubjectId"].Value = SubjectId == 0 ? System.Data.SqlTypes.SqlInt32.Null : SubjectId;

    oComm.Parameters.Add(new SqlParameter("@ProgramId", SqlDbType.Int));
    oComm.Parameters["@ProgramId"].Value = ProgramId == 0 ? System.Data.SqlTypes.SqlInt32.Null : ProgramId;

    oComm.Parameters.Add(new SqlParameter("@ProgramLevelId", SqlDbType.Int));
    oComm.Parameters["@ProgramLevelId"].Value = ProgramLevelId == 0 ? System.Data.SqlTypes.SqlInt32.Null : ProgramLevelId;

    oComm.Parameters.Add(new SqlParameter("@AcademicSession", SqlDbType.Int));
    oComm.Parameters["@AcademicSession"].Value = AcademicSession == 0 ? System.Data.SqlTypes.SqlInt32.Null : AcademicSession;

    oComm.Parameters.Add(new SqlParameter("@AcademicTerm", SqlDbType.Int));
    oComm.Parameters["@AcademicTerm"].Value = AcademicTerm == 0 ? System.Data.SqlTypes.SqlInt32.Null : AcademicTerm;

    oComm.Parameters.Add(new SqlParameter("@AddedBy", SqlDbType.Int));
    oComm.Parameters["@AddedBy"].Value = MembershipHelper.GetActiveUser().Teacher.IsAdmin ? System.Data.SqlTypes.SqlInt32.Null : MembershipHelper.GetActiveUserId;

    oComm.Parameters.Add(new SqlParameter("@EntityStatus", SqlDbType.Int));
    oComm.Parameters["@EntityStatus"].Value = status;

    SqlDataReader rdr = oComm.ExecuteReader();
    if (rdr.HasRows)
    {
    int _sn = 0;
    while (rdr.Read())
    {
    int publicStatus = _rdrHelper.getOrdinalInt32Value(rdr, "EntityStatus");
    _sn++;
    TestViewModel qList = new TestViewModel();
    qList.ProgramLevelId = _rdrHelper.getOrdinalInt32Value(rdr, "ProgramLevel");
    qList.ProgramLevelText = Extensions.ListEnums.GetProgramLevel().Skip(qList.ProgramLevelId - 1).First().Text;
    qList.AcademicTermId = _rdrHelper.getOrdinalInt32Value(rdr, "AcademicTerm");
    qList.AcademicTermText = Extensions.ListEnums.GetTermChoice().Skip(qList.AcademicTermId - 1).First().Text;
    qList.TestTitle = _rdrHelper.GetOrdinalStringValue(rdr, "Title");
    qList.ClassId = _rdrHelper.getOrdinalInt32Value(rdr, "ClassId");
    qList.ClassName = _rdrHelper.GetOrdinalStringValue(rdr, "ClassName");
    qList.SubjectName = _rdrHelper.GetOrdinalStringValue(rdr, "SubjectName");
    qList.SessionId = _rdrHelper.getOrdinalInt32Value(rdr, "Session");
    qList.TestId = _rdrHelper.getOrdinalInt32Value(rdr, "Id");
    qList.Duration = _rdrHelper.getOrdinalInt32Value(rdr, "Duration");
    qList.Status = _rdrHelper.getOrdinalBooleanValue(rdr, "Status");
    qList.QuestionCount = _rdrHelper.getOrdinalInt32Value(rdr, "QuestionNumber");
    qList.TestSn = _sn;
    qList.ResultExists = _rdrHelper.getOrdinalInt32Value(rdr, "ResultsCount") > 0;
    qList.AddedBy = _rdrHelper.getOrdinalInt32Value(rdr, "AddedBy");
    qList.Test.StartDateTime = _rdrHelper.getNullableOrdinalDatetimeValue(rdr, "StartDateTime");
    qList.Test.EndDateTime = _rdrHelper.getNullableOrdinalDatetimeValue(rdr, "EndDateTime");
    qList.Test.EntityStatus = publicStatus;
    sList.Add(qList);
    }
    }
    con.Close();
    }

    }
    }


    one my create page there is no field to pass the value for the entitystatus



    create test page



    but for the edit page there is a field to pass value into the entitystatus



    edit page



    the publish status is the field that gives the entity status value. The thing is after creating the test i'm redirected to the edit page to click the save button so that all entries will be saved into the databas3 but i did not click the save button i just went back to the index page which shows the list of tests.






    share|improve this answer

























      up vote
      0
      down vote













      the problem is not the test procedure, it from the code below there is nothing saving the enitystatus' value



          public bool insert_New_Test(string TestName, int Duration, int SessionYear, int ClassId, int SubjectId, bool Status, int AddedBy,
      int ProgramLevelId, int AcademicTerm, int questionSetUpType, out int id, DateTime startDateTime, DateTime endDateTime, int? testType)
      {
      bool functionReturnValue = false;
      id = 0;
      try
      {
      using (SqlConnection con = new SqlConnection(conn))
      {
      con.Open();
      SqlCommand oComm = new SqlCommand();
      using (oComm)
      {
      oComm.Connection = con;
      oComm.CommandType = CommandType.StoredProcedure;
      oComm.CommandText = "CMS_Test_Insert";

      oComm.Parameters.Add(new SqlParameter("@Title", SqlDbType.NVarChar));
      oComm.Parameters["@Title"].Value = TestName;

      oComm.Parameters.Add(new SqlParameter("@SubjectId", SqlDbType.Int));
      oComm.Parameters["@SubjectId"].Value = SubjectId;

      oComm.Parameters.Add(new SqlParameter("@ClassId", SqlDbType.Int));
      oComm.Parameters["@ClassId"].Value = ClassId;

      oComm.Parameters.Add(new SqlParameter("@Session", SqlDbType.Int));
      oComm.Parameters["@Session"].Value = SessionYear;

      oComm.Parameters.Add(new SqlParameter("@ProgramLevelId", SqlDbType.Int));
      oComm.Parameters["@ProgramLevelId"].Value = ProgramLevelId;

      oComm.Parameters.Add(new SqlParameter("@AcademicTerm", SqlDbType.Int));
      oComm.Parameters["@AcademicTerm"].Value = AcademicTerm;

      oComm.Parameters.Add(new SqlParameter("@Duration", SqlDbType.Int));
      oComm.Parameters["@Duration"].Value = Duration;

      oComm.Parameters.Add(new SqlParameter("@Status", SqlDbType.Bit));
      oComm.Parameters["@Status"].Value = Status;

      oComm.Parameters.Add(new SqlParameter("@AddedBy", SqlDbType.Int));
      oComm.Parameters["@AddedBy"].Value = AddedBy;


      oComm.Parameters.Add(new SqlParameter("@QuestionSetupType", SqlDbType.Int));
      oComm.Parameters["@QuestionSetupType"].Value = questionSetUpType;

      if (startDateTime > DateTime.MinValue)
      {
      oComm.Parameters.Add(new SqlParameter("@StartDateTime", SqlDbType.DateTime));
      oComm.Parameters["@StartDateTime"].Value = startDateTime;
      }
      if (endDateTime > DateTime.MinValue)
      {
      oComm.Parameters.Add(new SqlParameter("@EndDateTime", SqlDbType.DateTime));
      oComm.Parameters["@EndDateTime"].Value = endDateTime;
      }

      oComm.Parameters.Add(new SqlParameter("@TestType", SqlDbType.Int));
      oComm.Parameters["@TestType"].Value = testType;

      oComm.Parameters.Add(new SqlParameter("@Success", SqlDbType.Bit));
      oComm.Parameters["@Success"].Direction = ParameterDirection.Output;

      oComm.Parameters.Add(new SqlParameter("@TestId", SqlDbType.Int));
      oComm.Parameters["@TestId"].Direction = ParameterDirection.Output;
      oComm.ExecuteNonQuery();
      functionReturnValue = Convert.ToBoolean(oComm.Parameters["@Success"].Value);
      id = Convert.ToInt32(oComm.Parameters["@TestId"].Value);

      }
      con.Close();
      }

      }
      catch (SqlException ex)
      {
      Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
      functionReturnValue = false;
      }
      return functionReturnValue;

      }


      so when it try to get the value for the entitystatus the value is null



      public List<TestViewModel> get_List_Of_Test(int SubjectId, int ProgramLevelId, int AcademicTerm, int AcademicSession,
      int ProgramId, int status)
      {
      List<TestViewModel> sList = new List<TestViewModel>();
      try
      {
      using (SqlConnection con = new SqlConnection(conn))
      {
      con.Open();
      SqlCommand oComm = new SqlCommand();
      using (oComm)
      {
      oComm.Connection = con;
      oComm.CommandType = CommandType.StoredProcedure;
      oComm.CommandText = "CMS_Test_GetList";

      oComm.Parameters.Add(new SqlParameter("@SubjectId", SqlDbType.Int));
      oComm.Parameters["@SubjectId"].Value = SubjectId == 0 ? System.Data.SqlTypes.SqlInt32.Null : SubjectId;

      oComm.Parameters.Add(new SqlParameter("@ProgramId", SqlDbType.Int));
      oComm.Parameters["@ProgramId"].Value = ProgramId == 0 ? System.Data.SqlTypes.SqlInt32.Null : ProgramId;

      oComm.Parameters.Add(new SqlParameter("@ProgramLevelId", SqlDbType.Int));
      oComm.Parameters["@ProgramLevelId"].Value = ProgramLevelId == 0 ? System.Data.SqlTypes.SqlInt32.Null : ProgramLevelId;

      oComm.Parameters.Add(new SqlParameter("@AcademicSession", SqlDbType.Int));
      oComm.Parameters["@AcademicSession"].Value = AcademicSession == 0 ? System.Data.SqlTypes.SqlInt32.Null : AcademicSession;

      oComm.Parameters.Add(new SqlParameter("@AcademicTerm", SqlDbType.Int));
      oComm.Parameters["@AcademicTerm"].Value = AcademicTerm == 0 ? System.Data.SqlTypes.SqlInt32.Null : AcademicTerm;

      oComm.Parameters.Add(new SqlParameter("@AddedBy", SqlDbType.Int));
      oComm.Parameters["@AddedBy"].Value = MembershipHelper.GetActiveUser().Teacher.IsAdmin ? System.Data.SqlTypes.SqlInt32.Null : MembershipHelper.GetActiveUserId;

      oComm.Parameters.Add(new SqlParameter("@EntityStatus", SqlDbType.Int));
      oComm.Parameters["@EntityStatus"].Value = status;

      SqlDataReader rdr = oComm.ExecuteReader();
      if (rdr.HasRows)
      {
      int _sn = 0;
      while (rdr.Read())
      {
      int publicStatus = _rdrHelper.getOrdinalInt32Value(rdr, "EntityStatus");
      _sn++;
      TestViewModel qList = new TestViewModel();
      qList.ProgramLevelId = _rdrHelper.getOrdinalInt32Value(rdr, "ProgramLevel");
      qList.ProgramLevelText = Extensions.ListEnums.GetProgramLevel().Skip(qList.ProgramLevelId - 1).First().Text;
      qList.AcademicTermId = _rdrHelper.getOrdinalInt32Value(rdr, "AcademicTerm");
      qList.AcademicTermText = Extensions.ListEnums.GetTermChoice().Skip(qList.AcademicTermId - 1).First().Text;
      qList.TestTitle = _rdrHelper.GetOrdinalStringValue(rdr, "Title");
      qList.ClassId = _rdrHelper.getOrdinalInt32Value(rdr, "ClassId");
      qList.ClassName = _rdrHelper.GetOrdinalStringValue(rdr, "ClassName");
      qList.SubjectName = _rdrHelper.GetOrdinalStringValue(rdr, "SubjectName");
      qList.SessionId = _rdrHelper.getOrdinalInt32Value(rdr, "Session");
      qList.TestId = _rdrHelper.getOrdinalInt32Value(rdr, "Id");
      qList.Duration = _rdrHelper.getOrdinalInt32Value(rdr, "Duration");
      qList.Status = _rdrHelper.getOrdinalBooleanValue(rdr, "Status");
      qList.QuestionCount = _rdrHelper.getOrdinalInt32Value(rdr, "QuestionNumber");
      qList.TestSn = _sn;
      qList.ResultExists = _rdrHelper.getOrdinalInt32Value(rdr, "ResultsCount") > 0;
      qList.AddedBy = _rdrHelper.getOrdinalInt32Value(rdr, "AddedBy");
      qList.Test.StartDateTime = _rdrHelper.getNullableOrdinalDatetimeValue(rdr, "StartDateTime");
      qList.Test.EndDateTime = _rdrHelper.getNullableOrdinalDatetimeValue(rdr, "EndDateTime");
      qList.Test.EntityStatus = publicStatus;
      sList.Add(qList);
      }
      }
      con.Close();
      }

      }
      }


      one my create page there is no field to pass the value for the entitystatus



      create test page



      but for the edit page there is a field to pass value into the entitystatus



      edit page



      the publish status is the field that gives the entity status value. The thing is after creating the test i'm redirected to the edit page to click the save button so that all entries will be saved into the databas3 but i did not click the save button i just went back to the index page which shows the list of tests.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        the problem is not the test procedure, it from the code below there is nothing saving the enitystatus' value



            public bool insert_New_Test(string TestName, int Duration, int SessionYear, int ClassId, int SubjectId, bool Status, int AddedBy,
        int ProgramLevelId, int AcademicTerm, int questionSetUpType, out int id, DateTime startDateTime, DateTime endDateTime, int? testType)
        {
        bool functionReturnValue = false;
        id = 0;
        try
        {
        using (SqlConnection con = new SqlConnection(conn))
        {
        con.Open();
        SqlCommand oComm = new SqlCommand();
        using (oComm)
        {
        oComm.Connection = con;
        oComm.CommandType = CommandType.StoredProcedure;
        oComm.CommandText = "CMS_Test_Insert";

        oComm.Parameters.Add(new SqlParameter("@Title", SqlDbType.NVarChar));
        oComm.Parameters["@Title"].Value = TestName;

        oComm.Parameters.Add(new SqlParameter("@SubjectId", SqlDbType.Int));
        oComm.Parameters["@SubjectId"].Value = SubjectId;

        oComm.Parameters.Add(new SqlParameter("@ClassId", SqlDbType.Int));
        oComm.Parameters["@ClassId"].Value = ClassId;

        oComm.Parameters.Add(new SqlParameter("@Session", SqlDbType.Int));
        oComm.Parameters["@Session"].Value = SessionYear;

        oComm.Parameters.Add(new SqlParameter("@ProgramLevelId", SqlDbType.Int));
        oComm.Parameters["@ProgramLevelId"].Value = ProgramLevelId;

        oComm.Parameters.Add(new SqlParameter("@AcademicTerm", SqlDbType.Int));
        oComm.Parameters["@AcademicTerm"].Value = AcademicTerm;

        oComm.Parameters.Add(new SqlParameter("@Duration", SqlDbType.Int));
        oComm.Parameters["@Duration"].Value = Duration;

        oComm.Parameters.Add(new SqlParameter("@Status", SqlDbType.Bit));
        oComm.Parameters["@Status"].Value = Status;

        oComm.Parameters.Add(new SqlParameter("@AddedBy", SqlDbType.Int));
        oComm.Parameters["@AddedBy"].Value = AddedBy;


        oComm.Parameters.Add(new SqlParameter("@QuestionSetupType", SqlDbType.Int));
        oComm.Parameters["@QuestionSetupType"].Value = questionSetUpType;

        if (startDateTime > DateTime.MinValue)
        {
        oComm.Parameters.Add(new SqlParameter("@StartDateTime", SqlDbType.DateTime));
        oComm.Parameters["@StartDateTime"].Value = startDateTime;
        }
        if (endDateTime > DateTime.MinValue)
        {
        oComm.Parameters.Add(new SqlParameter("@EndDateTime", SqlDbType.DateTime));
        oComm.Parameters["@EndDateTime"].Value = endDateTime;
        }

        oComm.Parameters.Add(new SqlParameter("@TestType", SqlDbType.Int));
        oComm.Parameters["@TestType"].Value = testType;

        oComm.Parameters.Add(new SqlParameter("@Success", SqlDbType.Bit));
        oComm.Parameters["@Success"].Direction = ParameterDirection.Output;

        oComm.Parameters.Add(new SqlParameter("@TestId", SqlDbType.Int));
        oComm.Parameters["@TestId"].Direction = ParameterDirection.Output;
        oComm.ExecuteNonQuery();
        functionReturnValue = Convert.ToBoolean(oComm.Parameters["@Success"].Value);
        id = Convert.ToInt32(oComm.Parameters["@TestId"].Value);

        }
        con.Close();
        }

        }
        catch (SqlException ex)
        {
        Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
        functionReturnValue = false;
        }
        return functionReturnValue;

        }


        so when it try to get the value for the entitystatus the value is null



        public List<TestViewModel> get_List_Of_Test(int SubjectId, int ProgramLevelId, int AcademicTerm, int AcademicSession,
        int ProgramId, int status)
        {
        List<TestViewModel> sList = new List<TestViewModel>();
        try
        {
        using (SqlConnection con = new SqlConnection(conn))
        {
        con.Open();
        SqlCommand oComm = new SqlCommand();
        using (oComm)
        {
        oComm.Connection = con;
        oComm.CommandType = CommandType.StoredProcedure;
        oComm.CommandText = "CMS_Test_GetList";

        oComm.Parameters.Add(new SqlParameter("@SubjectId", SqlDbType.Int));
        oComm.Parameters["@SubjectId"].Value = SubjectId == 0 ? System.Data.SqlTypes.SqlInt32.Null : SubjectId;

        oComm.Parameters.Add(new SqlParameter("@ProgramId", SqlDbType.Int));
        oComm.Parameters["@ProgramId"].Value = ProgramId == 0 ? System.Data.SqlTypes.SqlInt32.Null : ProgramId;

        oComm.Parameters.Add(new SqlParameter("@ProgramLevelId", SqlDbType.Int));
        oComm.Parameters["@ProgramLevelId"].Value = ProgramLevelId == 0 ? System.Data.SqlTypes.SqlInt32.Null : ProgramLevelId;

        oComm.Parameters.Add(new SqlParameter("@AcademicSession", SqlDbType.Int));
        oComm.Parameters["@AcademicSession"].Value = AcademicSession == 0 ? System.Data.SqlTypes.SqlInt32.Null : AcademicSession;

        oComm.Parameters.Add(new SqlParameter("@AcademicTerm", SqlDbType.Int));
        oComm.Parameters["@AcademicTerm"].Value = AcademicTerm == 0 ? System.Data.SqlTypes.SqlInt32.Null : AcademicTerm;

        oComm.Parameters.Add(new SqlParameter("@AddedBy", SqlDbType.Int));
        oComm.Parameters["@AddedBy"].Value = MembershipHelper.GetActiveUser().Teacher.IsAdmin ? System.Data.SqlTypes.SqlInt32.Null : MembershipHelper.GetActiveUserId;

        oComm.Parameters.Add(new SqlParameter("@EntityStatus", SqlDbType.Int));
        oComm.Parameters["@EntityStatus"].Value = status;

        SqlDataReader rdr = oComm.ExecuteReader();
        if (rdr.HasRows)
        {
        int _sn = 0;
        while (rdr.Read())
        {
        int publicStatus = _rdrHelper.getOrdinalInt32Value(rdr, "EntityStatus");
        _sn++;
        TestViewModel qList = new TestViewModel();
        qList.ProgramLevelId = _rdrHelper.getOrdinalInt32Value(rdr, "ProgramLevel");
        qList.ProgramLevelText = Extensions.ListEnums.GetProgramLevel().Skip(qList.ProgramLevelId - 1).First().Text;
        qList.AcademicTermId = _rdrHelper.getOrdinalInt32Value(rdr, "AcademicTerm");
        qList.AcademicTermText = Extensions.ListEnums.GetTermChoice().Skip(qList.AcademicTermId - 1).First().Text;
        qList.TestTitle = _rdrHelper.GetOrdinalStringValue(rdr, "Title");
        qList.ClassId = _rdrHelper.getOrdinalInt32Value(rdr, "ClassId");
        qList.ClassName = _rdrHelper.GetOrdinalStringValue(rdr, "ClassName");
        qList.SubjectName = _rdrHelper.GetOrdinalStringValue(rdr, "SubjectName");
        qList.SessionId = _rdrHelper.getOrdinalInt32Value(rdr, "Session");
        qList.TestId = _rdrHelper.getOrdinalInt32Value(rdr, "Id");
        qList.Duration = _rdrHelper.getOrdinalInt32Value(rdr, "Duration");
        qList.Status = _rdrHelper.getOrdinalBooleanValue(rdr, "Status");
        qList.QuestionCount = _rdrHelper.getOrdinalInt32Value(rdr, "QuestionNumber");
        qList.TestSn = _sn;
        qList.ResultExists = _rdrHelper.getOrdinalInt32Value(rdr, "ResultsCount") > 0;
        qList.AddedBy = _rdrHelper.getOrdinalInt32Value(rdr, "AddedBy");
        qList.Test.StartDateTime = _rdrHelper.getNullableOrdinalDatetimeValue(rdr, "StartDateTime");
        qList.Test.EndDateTime = _rdrHelper.getNullableOrdinalDatetimeValue(rdr, "EndDateTime");
        qList.Test.EntityStatus = publicStatus;
        sList.Add(qList);
        }
        }
        con.Close();
        }

        }
        }


        one my create page there is no field to pass the value for the entitystatus



        create test page



        but for the edit page there is a field to pass value into the entitystatus



        edit page



        the publish status is the field that gives the entity status value. The thing is after creating the test i'm redirected to the edit page to click the save button so that all entries will be saved into the databas3 but i did not click the save button i just went back to the index page which shows the list of tests.






        share|improve this answer












        the problem is not the test procedure, it from the code below there is nothing saving the enitystatus' value



            public bool insert_New_Test(string TestName, int Duration, int SessionYear, int ClassId, int SubjectId, bool Status, int AddedBy,
        int ProgramLevelId, int AcademicTerm, int questionSetUpType, out int id, DateTime startDateTime, DateTime endDateTime, int? testType)
        {
        bool functionReturnValue = false;
        id = 0;
        try
        {
        using (SqlConnection con = new SqlConnection(conn))
        {
        con.Open();
        SqlCommand oComm = new SqlCommand();
        using (oComm)
        {
        oComm.Connection = con;
        oComm.CommandType = CommandType.StoredProcedure;
        oComm.CommandText = "CMS_Test_Insert";

        oComm.Parameters.Add(new SqlParameter("@Title", SqlDbType.NVarChar));
        oComm.Parameters["@Title"].Value = TestName;

        oComm.Parameters.Add(new SqlParameter("@SubjectId", SqlDbType.Int));
        oComm.Parameters["@SubjectId"].Value = SubjectId;

        oComm.Parameters.Add(new SqlParameter("@ClassId", SqlDbType.Int));
        oComm.Parameters["@ClassId"].Value = ClassId;

        oComm.Parameters.Add(new SqlParameter("@Session", SqlDbType.Int));
        oComm.Parameters["@Session"].Value = SessionYear;

        oComm.Parameters.Add(new SqlParameter("@ProgramLevelId", SqlDbType.Int));
        oComm.Parameters["@ProgramLevelId"].Value = ProgramLevelId;

        oComm.Parameters.Add(new SqlParameter("@AcademicTerm", SqlDbType.Int));
        oComm.Parameters["@AcademicTerm"].Value = AcademicTerm;

        oComm.Parameters.Add(new SqlParameter("@Duration", SqlDbType.Int));
        oComm.Parameters["@Duration"].Value = Duration;

        oComm.Parameters.Add(new SqlParameter("@Status", SqlDbType.Bit));
        oComm.Parameters["@Status"].Value = Status;

        oComm.Parameters.Add(new SqlParameter("@AddedBy", SqlDbType.Int));
        oComm.Parameters["@AddedBy"].Value = AddedBy;


        oComm.Parameters.Add(new SqlParameter("@QuestionSetupType", SqlDbType.Int));
        oComm.Parameters["@QuestionSetupType"].Value = questionSetUpType;

        if (startDateTime > DateTime.MinValue)
        {
        oComm.Parameters.Add(new SqlParameter("@StartDateTime", SqlDbType.DateTime));
        oComm.Parameters["@StartDateTime"].Value = startDateTime;
        }
        if (endDateTime > DateTime.MinValue)
        {
        oComm.Parameters.Add(new SqlParameter("@EndDateTime", SqlDbType.DateTime));
        oComm.Parameters["@EndDateTime"].Value = endDateTime;
        }

        oComm.Parameters.Add(new SqlParameter("@TestType", SqlDbType.Int));
        oComm.Parameters["@TestType"].Value = testType;

        oComm.Parameters.Add(new SqlParameter("@Success", SqlDbType.Bit));
        oComm.Parameters["@Success"].Direction = ParameterDirection.Output;

        oComm.Parameters.Add(new SqlParameter("@TestId", SqlDbType.Int));
        oComm.Parameters["@TestId"].Direction = ParameterDirection.Output;
        oComm.ExecuteNonQuery();
        functionReturnValue = Convert.ToBoolean(oComm.Parameters["@Success"].Value);
        id = Convert.ToInt32(oComm.Parameters["@TestId"].Value);

        }
        con.Close();
        }

        }
        catch (SqlException ex)
        {
        Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
        functionReturnValue = false;
        }
        return functionReturnValue;

        }


        so when it try to get the value for the entitystatus the value is null



        public List<TestViewModel> get_List_Of_Test(int SubjectId, int ProgramLevelId, int AcademicTerm, int AcademicSession,
        int ProgramId, int status)
        {
        List<TestViewModel> sList = new List<TestViewModel>();
        try
        {
        using (SqlConnection con = new SqlConnection(conn))
        {
        con.Open();
        SqlCommand oComm = new SqlCommand();
        using (oComm)
        {
        oComm.Connection = con;
        oComm.CommandType = CommandType.StoredProcedure;
        oComm.CommandText = "CMS_Test_GetList";

        oComm.Parameters.Add(new SqlParameter("@SubjectId", SqlDbType.Int));
        oComm.Parameters["@SubjectId"].Value = SubjectId == 0 ? System.Data.SqlTypes.SqlInt32.Null : SubjectId;

        oComm.Parameters.Add(new SqlParameter("@ProgramId", SqlDbType.Int));
        oComm.Parameters["@ProgramId"].Value = ProgramId == 0 ? System.Data.SqlTypes.SqlInt32.Null : ProgramId;

        oComm.Parameters.Add(new SqlParameter("@ProgramLevelId", SqlDbType.Int));
        oComm.Parameters["@ProgramLevelId"].Value = ProgramLevelId == 0 ? System.Data.SqlTypes.SqlInt32.Null : ProgramLevelId;

        oComm.Parameters.Add(new SqlParameter("@AcademicSession", SqlDbType.Int));
        oComm.Parameters["@AcademicSession"].Value = AcademicSession == 0 ? System.Data.SqlTypes.SqlInt32.Null : AcademicSession;

        oComm.Parameters.Add(new SqlParameter("@AcademicTerm", SqlDbType.Int));
        oComm.Parameters["@AcademicTerm"].Value = AcademicTerm == 0 ? System.Data.SqlTypes.SqlInt32.Null : AcademicTerm;

        oComm.Parameters.Add(new SqlParameter("@AddedBy", SqlDbType.Int));
        oComm.Parameters["@AddedBy"].Value = MembershipHelper.GetActiveUser().Teacher.IsAdmin ? System.Data.SqlTypes.SqlInt32.Null : MembershipHelper.GetActiveUserId;

        oComm.Parameters.Add(new SqlParameter("@EntityStatus", SqlDbType.Int));
        oComm.Parameters["@EntityStatus"].Value = status;

        SqlDataReader rdr = oComm.ExecuteReader();
        if (rdr.HasRows)
        {
        int _sn = 0;
        while (rdr.Read())
        {
        int publicStatus = _rdrHelper.getOrdinalInt32Value(rdr, "EntityStatus");
        _sn++;
        TestViewModel qList = new TestViewModel();
        qList.ProgramLevelId = _rdrHelper.getOrdinalInt32Value(rdr, "ProgramLevel");
        qList.ProgramLevelText = Extensions.ListEnums.GetProgramLevel().Skip(qList.ProgramLevelId - 1).First().Text;
        qList.AcademicTermId = _rdrHelper.getOrdinalInt32Value(rdr, "AcademicTerm");
        qList.AcademicTermText = Extensions.ListEnums.GetTermChoice().Skip(qList.AcademicTermId - 1).First().Text;
        qList.TestTitle = _rdrHelper.GetOrdinalStringValue(rdr, "Title");
        qList.ClassId = _rdrHelper.getOrdinalInt32Value(rdr, "ClassId");
        qList.ClassName = _rdrHelper.GetOrdinalStringValue(rdr, "ClassName");
        qList.SubjectName = _rdrHelper.GetOrdinalStringValue(rdr, "SubjectName");
        qList.SessionId = _rdrHelper.getOrdinalInt32Value(rdr, "Session");
        qList.TestId = _rdrHelper.getOrdinalInt32Value(rdr, "Id");
        qList.Duration = _rdrHelper.getOrdinalInt32Value(rdr, "Duration");
        qList.Status = _rdrHelper.getOrdinalBooleanValue(rdr, "Status");
        qList.QuestionCount = _rdrHelper.getOrdinalInt32Value(rdr, "QuestionNumber");
        qList.TestSn = _sn;
        qList.ResultExists = _rdrHelper.getOrdinalInt32Value(rdr, "ResultsCount") > 0;
        qList.AddedBy = _rdrHelper.getOrdinalInt32Value(rdr, "AddedBy");
        qList.Test.StartDateTime = _rdrHelper.getNullableOrdinalDatetimeValue(rdr, "StartDateTime");
        qList.Test.EndDateTime = _rdrHelper.getNullableOrdinalDatetimeValue(rdr, "EndDateTime");
        qList.Test.EntityStatus = publicStatus;
        sList.Add(qList);
        }
        }
        con.Close();
        }

        }
        }


        one my create page there is no field to pass the value for the entitystatus



        create test page



        but for the edit page there is a field to pass value into the entitystatus



        edit page



        the publish status is the field that gives the entity status value. The thing is after creating the test i'm redirected to the edit page to click the save button so that all entries will be saved into the databas3 but i did not click the save button i just went back to the index page which shows the list of tests.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 at 12:38









        Timothy

        34




        34






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427846%2fim-not-getting-the-right-result-with-this-store-procedure%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks