Search code examples
c#stored-proceduresparametersdevexpress

Create XtraReports with parameters with: (stored procedures with parameters)


I have a question related with Xtra Reports and stored Procedures with parameters.

I've been using XtraReports not for long, yet I have learned a lot. The thing is that I haven't been able to complete one task the right way.

Let me explain:

In my DataSet I have one SP_get_singleRecord which has 2 parameters (@ID, @TYPE) /*string,int*/ and the table has 6 columns.

So, I add the dataset(dataset1), dataMember(SP_get_singleRecord) and dataAdapter(SP_get_singleRecord_TableAdapter) to the xtraReport. I use the wizard to set the fields on place.

Now I go to the parameter section on xtrareports' fieldList and I add parameter ID as string and TYPE as int.

Then I go to the filter string and set the parameters like this: [ID] = ?ID And [TYPE] = ?TYPE

Now, I go to the windowsForm -> print_simplebuttonEvent_OnClick

I pass the parameters silently like this:

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

Then I get an error message that says: Error when trying to populate the datasource. The following exception was thrown: Procedure or function 'SP_getSingleRecord' expects parameter '@ID' which was not supplied.

According to that, the parameters I've passed never reached the stored procedure. I'm trying to get a single record before printing the report but I don't know what am I missing here...

I've tried another way to do it but that involves changing the 'SP_getSingleRecord' for 'SP_getALLRecords' (with no parameters). That returns around 6500+ records and then filter them from the side of the report but that takes 9 seconds which is not acceptable... It works, but it's not the right way...

I hope I've made myself clear. I hope you can help me.

Thanks in advance.

Alfred.


Solution

  • Try This:

    • set connection strings

      SP_get_singleRecord_TableAdapter.Connection.ConnectionString
      

      if you have any

    • then add this to your Button click event (to the start of it...)

      SP_get_singleRecord_TableAdapter.Fill(dataset1.Yourdatatable, Convert.ToInt32(lookUpEdit_Type.EditValue), lookUpEdit_id.EditValue.ToString())
      
    • On your XtraReport remove your data adapter:

      dataAdapter(SP_get_singleRecord_TableAdapter)
      
    • also make sure that at the very bottom of yor XtraReport only the DataSet is shown (no data members, no table adapters..)