Question

I am sure i have exact column name but when i try to get it using C# an error comes up that "Column name "TheoryCourseDate2" doesn't belong to table" I have stored procedure which gets count from another table and i save count results in my created Columns named "TheoryCourseDate1" and "TheoryCourseDate2"

Here is my stored procedure :

SELECT COUNT(NULLIF(dt_UserTTrainingDate1,'')) as TheoryCourseDate1 FROM ref_CourseRegistration_Users
SELECT COUNT(NULLIF(dt_UserTTrainingDate2,'')) as TheoryCourseDate2 FROM ref_CourseRegistration_Users

I get count results in code in DataRow and it works fine for column "TheoryCourseDate1" but not works for column "TheoryCourseDate2" even column name is correct. Here is C# Code :

SqlParameter[] parm = new SqlParameter[0];
DataRow oRow = SqlHelper.ExecuteRow(this._connString, CommandType.StoredProcedure, SQL_REF_GET_COUNT, parm);

if (oRow != null)
{
    oCourseCount.TheoryCourseDate1Count = Common.CheckStringNull(oRow["TheoryCourseDate1"]);
    oCourseCount.TheoryCourseDate2Count = Common.CheckStringNull(oRow["TheoryCourseDate2"]);
    return oCourseCount;
}

I am stuck with this as i dont think there is any error in my code etc but may be some other way can eliminate column name errors

Was it helpful?

Solution

You have two separate selects and so the results are not on the same row. Try this:

SELECT COUNT(NULLIF(dt_UserTTrainingDate1,'')) as TheoryCourseDate1,
  COUNT(NULLIF(dt_UserTTrainingDate2,'')) as TheoryCourseDate2 
FROM ref_CourseRegistration_Users
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top