如何将Datagridview详细信息导出到crystal报表

时间:2015-02-12 07:36:11

标签: c# linq crystal-reports

我在我的项目中使用Linq到Sql,并且数据网格视图由一个名为Get_All_Incomes的存储过程填充。

我设计了一个Crystal Report来查看gridview中的数据,但是有一个例外

  

DataSet不支持System.Nullable<>

我使用此代码填充gridview

dgvIncome.DataSource = CLS_Incomes.Get_All_Incomes().ToList();

我使用此方法过滤gridview

string nameFilter = txtCust.Text;
string mediaFilter = comboMedia.SelectedIndex > 0 ? comboMedia.Text : "";
string currencyFilter = comboCurr.SelectedIndex > 0 ? comboCurr.Text :"";
string motalabahFilter = txtMot.Text;
string sanadFilter = txtSanad.Text;
string incomeFilter = txtIncome.Text;
DateTime? fromDate = radioFrom.Checked ? dateTimePicker1.Value.Date : (DateTime?)null;
DateTime? toDate = radioFrom.Checked ? dateTimePicker2.Value.Date : (DateTime?) null;

        using (dbDataContext db = new dbDataContext())
        {
            var result = from p in db.Get_All_Incomes()
                where
                    (nameFilter.Length > 0 && p.CustomersName.Contains(nameFilter) || nameFilter.Length == 0)
                    && (mediaFilter.Length > 0 && p.Name == mediaFilter || mediaFilter.Length == 0)
                    && (currencyFilter.Length > 0 && p.CurrencyName == currencyFilter || currencyFilter.Length == 0)
                    && (motalabahFilter.Length > 0 && p.Motalabah == motalabahFilter || motalabahFilter.Length == 0)
                    && (sanadFilter.Length > 0 && p.Sanad == sanadFilter || sanadFilter.Length == 0)
                    && (incomeFilter.Length > 0 && p.Income.ToString() == incomeFilter || incomeFilter.Length == 0)
                    &&
                    ((fromDate == null || toDate == null) ||
                     (fromDate != null && toDate != null && p.SanadDate >= fromDate && p.SanadDate <= toDate))

                select p;


            dgvIncome.DataSource = result.ToList();

最后使用此按钮调用报告

btnReport.Cursor = Cursors.WaitCursor;
Reports.Rpt rpt = new Reports.Rpt();
rpt.SetDataSource(dgvIncome.DataSource);
FRM_Report frm = new FRM_Report();
btnReport.Cursor = Cursors.Default;
frm.ShowDialog();

1 个答案:

答案 0 :(得分:0)

虽然您的上述代码似乎没问题,但请检查您的&#34; date ... null&#34;代码行。这可能是问题所在。您是否尝试跟踪提供异常的代码?另外,你是如何设计水晶报告的?我怀疑问题在于填充有问题的数据集的方式。请告诉我你的发现。

请记住标记为&#34;已回答&#34;如果这有助于你。

相关问题