0

我正在尝试显示数据库表中的一些数据,但它显示了按摩,

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

五月查询是..

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();
4

1 回答 1

0

你可以试试这个:

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

或者

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

于 2013-06-11T06:01:35.977 回答