如何在两个日期范围之间显示数据

时间:2013-06-11 05:37:25

标签: c# sql reporting rdlc

我试图从数据库表中显示一些数据,但它显示按摩,

"Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."

May Query is ..

SELECT        tblEmployeeInfo.EmpCode, tblEmployeeInfo.EmpName,     tblEmployeeInfo.EmpDepart, tblEmployeeInfo.EmpDesig, tblAtData.card_no, CONVERT(varchar, 
                         CONVERT(datetime, tblAtData.d_card), 112) AS Date,     CAST(LEFT(MIN(tblAtData.t_card), 2) + ':' + RIGHT(LEFT(MIN(tblAtData.t_card), 4), 2) 
                     + ':' + RIGHT(LEFT(MIN(tblAtData.t_card), 6), 2) AS TIME) AS Entrytime, CASE WHEN (CAST(LEFT(MAX(tblAtData.t_card), 2) 
                     + ':' + RIGHT(LEFT(MAX(tblAtData.t_card), 4), 2) + ':' + RIGHT(LEFT(MAX(tblAtData.t_card), 6), 2) AS TIME)) 
                     > tblSettings.StOutTime THEN tblSettings.StOutTime WHEN (CAST(LEFT(MAX(tblAtData.t_card), 2) + ':' + RIGHT(LEFT(MAX(tblAtData.t_card), 4), 2) 
                     + ':' + RIGHT(LEFT(MAX(tblAtData.t_card), 6), 2) AS TIME)) <= tblSettings.StOutTime THEN (CAST(LEFT(MAX(tblAtData.t_card), 2) 
                     + ':' + RIGHT(LEFT(MAX(tblAtData.t_card), 4), 2) + ':' + RIGHT(LEFT(MAX(tblAtData.t_card), 6), 2) AS TIME)) END AS OutTime, DATEDIFF(hour, 
                     CAST(LEFT(MIN(tblAtData.t_card), 2) + ':' + RIGHT(LEFT(MIN(tblAtData.t_card), 4), 2) AS TIME), CAST(LEFT(MAX(tblAtData.t_card), 2) 
                     + ':' + RIGHT(LEFT(MAX(tblAtData.t_card), 4), 2) AS TIME)) AS WH, CASE WHEN (DATEDIFF(hour, CAST(LEFT(MIN(tblAtData.t_card), 2) 
                     + ':' + RIGHT(LEFT(MIN(tblAtData.t_card), 4), 2) AS TIME), CAST(LEFT(MAX(tblAtData.t_card), 2) + ':' + RIGHT(LEFT(MAX(tblAtData.t_card), 4), 2) AS TIME)) 
                     - tblSettings.StWH) <= 0 THEN '0' WHEN (DATEDIFF(hour, CAST(LEFT(MIN(tblAtData.t_card), 2) + ':' + RIGHT(LEFT(MIN(tblAtData.t_card), 4), 2) AS TIME), 
                     CAST(LEFT(MAX(tblAtData.t_card), 2) + ':' + RIGHT(LEFT(MAX(tblAtData.t_card), 4), 2) AS TIME)) - 8) >= 2 THEN tblSettings.StOTH END AS OT, 
                     CASE WHEN CONVERT(datetime, (CAST(LEFT(MIN(tblAtData.t_card), 2) + ':' + RIGHT(LEFT(MIN(tblAtData.t_card), 4), 2) + ':' + RIGHT(LEFT(MIN(tblAtData.t_card),
                      6), 2) AS TIME))) > CONVERT(datetime, tblSettings.StEntryTime, 8) THEN 'Late' END AS ComingSate
FROM            tblEmployeeInfo INNER JOIN
                     tblAtData ON tblEmployeeInfo.EmpCardID = tblAtData.card_no INNER     JOIN
                     tblSettings ON tblSettings.StName = 'Setting'
WHERE        (tblAtData.d_card BETWEEN @sd AND @ed) AND (tblEmployeeInfo.EmpCode = @cd)
GROUP BY tblEmployeeInfo.EmpCode, tblEmployeeInfo.EmpName, tblEmployeeInfo.EmpDepart,     tblEmployeeInfo.EmpDesig, tblAtData.card_no, tblAtData.d_card, 
                     tblSettings.StEntryTime, tblSettings.StOTH, tblSettings.StWH,     tblSettings.StOutTime
   ORDER BY tblAtData.d_card DESC

C#代码是......

DateTime date = Convert.ToDateTime(RadDatePicker1.DbSelectedDate);    
DateTime date1 = Convert.ToDateTime(RadDatePicker2.DbSelectedDate);

    string st = date.ToString("yyyyMMdd");

    string st1 = date1.ToString("yyyyMMdd");


    AttendanceDataSetTableAdapters.tblAtData4TableAdapter adptAtnRange = new AttendanceDataSetTableAdapters.tblAtData4TableAdapter();
    AttendanceDataSet.tblAtData4DataTable tblAtnRange = new AttendanceDataSet.tblAtData4DataTable();

    adptAtnRange.FillAllRange((tblAtnRange), st, st1, RadTextBox1.Text);

    ReportDataSource mds = new ReportDataSource("DataSetByRange", (DataTable)tblAtnRange);

    this.ReportViewer1.LocalReport.DataSources.Clear();
    this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("AttendenceByRange.rdlc");
    //this.ReportViewer1.LocalReport.DataSources.Add(mds);
    this.ReportViewer1.LocalReport.DataSources.Add(mds);
    this.ReportViewer1.LocalReport.Refresh();

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

检查您正在使用的数据库表中列的所有MaxLength属性。 是否有您使用nvarchar(max)或varchar(max)值的列? 如果您使用这样的长度然后将其更改为-1,我希望它适合您。

您可以通过将DataSet的enforce Constraint属性设置为False来避免错误。 那就是禁用约束属性。