2015-02-12 66 views
0

我在我的項目中使用Linq to Sql,並通過名爲Get_All_Incomes的存儲過程填充datagridview。如何導出Datagridview細節到水晶報表

我設計了一個水晶報表,以在GridView查看數據,但有一個例外

集不支持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(); 

回答

0

雖然上面的代碼似乎罰款,檢查你的「約會......空」的代碼行的報告。這可能是問題所在。你有沒有嘗試跟蹤出現異常的代碼?另外,你是如何設計你的水晶報告的?我懷疑問題在於數據集的填充方式。請讓我知道你的發現。

記得標記爲「已回答」,如果這有助於你。