我确信我有确切的列名,但是当我尝试使用C#时,会出现错误,#34;列名称" TheoryCourseDate2"不属于表" 我有一个存储过程从另一个表中获取计数,我将计数结果保存在我创建的名为" TheoryCourseDate1"和" TheoryCourseDate2"
这是我的存储过程:
SELECT COUNT(NULLIF(dt_UserTTrainingDate1,'')) as TheoryCourseDate1 FROM ref_CourseRegistration_Users
SELECT COUNT(NULLIF(dt_UserTTrainingDate2,'')) as TheoryCourseDate2 FROM ref_CourseRegistration_Users
我在DataRow的代码中得到了计数结果,它适用于列" TheoryCourseDate1"但不适用于专栏" TheoryCourseDate2"偶数列名是正确的。 这是C#代码:
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;
}
我坚持这个,因为我不认为我的代码中有任何错误,但可能是其他一些方法可以消除列名错误
答案 0 :(得分:2)
您有两个单独的选择,因此结果不在同一行。试试这个:
SELECT COUNT(NULLIF(dt_UserTTrainingDate1,'')) as TheoryCourseDate1,
COUNT(NULLIF(dt_UserTTrainingDate2,'')) as TheoryCourseDate2
FROM ref_CourseRegistration_Users