我已经声明了变量并且它返回了正确的值但是我不明白为什么我仍然收到这个错误。
sqlString.Append( " SELECT Medication.Description + ' - ' + Medication.Strength + ' - ' + Medication.MedicationCode as DrugName, Resident.Title + ' ' + Resident.firstName + ' ' + Resident.Surname AS Resident, MedicationDispenseTimeslot.MedicationDosageBarcode, 0 AS checkBox " );
sqlString.Append( " FROM Medication INNER JOIN MedicationDispense ON Medication.MedicationID = MedicationDispense.MedicationID INNER JOIN Resident ON MedicationDispense.ResidentID = Resident.ResidentID INNER JOIN MedicationDispenseStatus ON MedicationDispense.MedicationDispenseStatusID = MedicationDispenseStatus.MedicationDispenseStatusID INNER JOIN MedicationDispenseTimeslot ON MedicationDispense.MedicationDispenseID = MedicationDispenseTimeslot.MedicationDispenseID WHERE (MedicationDispenseStatus.MedicationDispenseStatusID = 2) and MedicationDispense.MedicationDispenseID in (select MedicationDispenseID from dbo.MedicationDispenseHistory where DATEDIFF(d, 0, DateTimeStamp) =DATEDIFF(d, 0, GETDATE()) and MedicationDispenseStatusID=2) AND MedicationDispense.ResidentID = @residentID " );
sqlString.Append( " AND (MedicationDispense.MedicationDispenseStatusID > 1) AND ");
sqlString.Append( " 1 = (CASE WHEN MedicationDispense.StopDate IS NULL " );
sqlString.Append( " THEN (CASE WHEN MedicationDispense.StartDate <= @periodEndDate THEN 1 ELSE 0 END) " );
sqlString.Append( " ELSE " );
sqlString.Append( " CASE WHEN (MedicationDispense.StartDate between @periodStartDate and @periodEndDate) " );
sqlString.Append( " OR " );
sqlString.Append( " (MedicationDispense.StopDate between @periodStartDate and @periodEndDate) " );
sqlString.Append( " OR " );
sqlString.Append( " (MedicationDispense.StartDate < @periodStartDate and MedicationDispense.StopDate > @periodEndDate) " );
sqlString.Append( " GROUP BY Medication.Description + ' - ' + Medication.Strength + ' - ' + Medication.MedicationCode, Resident.Title + ' ' + Resident.firstName + ' ' + Resident.Surname , MedicationDispenseTimeslot.MedicationDosageBarcode " );
command = new SqlCommand(sqlString.ToString(), connection);
command.Parameters.Add( "@residentID", SqlDbType.Int ).Value = residentID.ToString();
command.Parameters.Add("@periodStartDate", SqlDbType.DateTime).Value = Helper.GetValue(periodStartDate);
command.Parameters.Add("@periodEndDate", SqlDbType.DateTime).Value = Helper.GetValue(periodEndDate);
编辑
command = new SqlCommand( sqlString.ToString(), connection );
SqlDataAdapter dataAdapter = new SqlDataAdapter( command );
dataAdapter.Fill( ds, "dataTable" );
return ds;