我有一個與Xtra Reports和帶有參數的存儲過程相關的問題。用以下參數創建XtraReports:(帶有參數的存儲過程)
我一直在使用XtraReports不長,但我學到了很多東西。問題是我無法以正確的方式完成一項任務。
讓我解釋一下:
在我的數據集我有一個SP_get_singleRecord
其中有2個參數(@ID, @TYPE) /*string,int*/
和表有6列。
因此,我將dataset(dataset1)
,dataMember(SP_get_singleRecord)
和dataAdapter(SP_get_singleRecord_TableAdapter)
添加到xtraReport。 我使用嚮導來設置放置的字段。
現在我去上xtrareports' FieldList中的參數部分,我添加參數ID
爲string
和TYPE
爲int
。
然後我去過濾字符串,並設置這樣的參數: [ID] = ?ID And [TYPE] = ?TYPE
現在,我去windowsForm - > print_simplebuttonEvent_OnClick
我默默傳遞的參數是這樣的:
private void btn_print_Click(object sender, EventArgs e)
{
//convert parameters from controls
int type = Convert.ToInt32(lookUpEdit_Type.EditValue);
string id = lookUpEdit_id.EditValue.ToString();
// Create a report instance
Xtrareport report = new Xtrareport();
// Obtain a parameter, and set its value.
report.ID.Value = id;
report.TYPE.Value = type;
// Hide the Parameters UI from end-users.
report.ID.Visible=false;
report.TYPE.Visible = false;
// Show the report's print preview.
report.ShowPreview();
}
然後,我收到一條錯誤消息:Error when trying to populate the datasource. The following exception was thrown: Procedure or function 'SP_getSingleRecord' expects parameter '@ID' which was not supplied.
據此,我傳遞的參數永遠不會到達存儲過程。 我試圖打印報表之前得到一個單一的記錄,但我不知道我錯過了...
我嘗試另一種方式來做到這一點,但涉及更改「SP_getSingleRecord '爲'SP_getALLRecords'(不帶參數)。返回圍繞6500+記錄,然後從報告的一側進行篩選但這需要9秒,這是不能接受的...... 它的工作原理,但它是不正確的做法...
我希望我我已經明確表示了。 我希望你能幫助我。
在此先感謝。
Alfred。
您無需默認傳遞參數,並且在初始化報告後立即傳遞「Report.DataSource = dataset1.SP_get_singleRecord」。 – Milen 2013-04-23 12:30:15