Vikas
Vikas

Reputation: 17

How to bind DevExpress XtraReport by Query String

Can anybody tell me how I can bind a DevExpress XtraReport by Query String?

I want to show only the ID value of 8 in the report, I am using a store procedure to get data.

SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
        SqlCommand cmd = new SqlCommand("GetLabReport", connection);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@PID", SqlDbType.Int).Value = Request.QueryString["ID"].ToString();
        connection.Open();
        SqlDataAdapter DA = new SqlDataAdapter(cmd);
        DataTable DT = new DataTable();
        XtraReport1 Rept = new XtraReport1();
        string path = (Server.MapPath("App_Code/XtraReport1.cs"));
        DA.Fill(DT);
        connection.Close();
        if(DT.Rows.Count>0)
        {

        }

The above works fine with Crystal Reports but not with DevExpress XtraReports.

Upvotes: 0

Views: 1943

Answers (1)

Niranjan Singh
Niranjan Singh

Reputation: 18290

I suggest you to create report parameters and then set the parameter value using the query string.

See the comments on below thread:
Report Designer using SQL Server Stored Procedure as data source, generates .Net exception.

Add a Report's Parameters and then map it to your query parameter. Then pass the value from Request.QueryString to the Parameter.Value property

Example:

protected void Page_Load(object sender, EventArgs e) {
            XtraReport3 report = new XtraReport3();
            report.Parameters[0].Value = Request["MyParam"];
            ASPxDocumentViewer1.Report = report;
        }

References:
Passing querystring values to a report
How to use parameter from querystring to show report
Parameters support thru URL QueryString in XtraReports?
How to pass QueryString parameter into Report (master-detail) c#

Upvotes: 1

Related Questions