Click here to Skip to main content
15,903,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have attached the code i used, here the error is showing near sqlhelper. i need some other alternative code. If any one can help me, please help.

C#
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Reporting.WebForms;

public partial class ReportViewerLocalMode : System.Web.UI.Page
{
    public string thisConnectionString = 
       ConfigurationManager.ConnectionStrings[
       "NorthwindConnectionString"].ConnectionString;

    /*I used the following statement to show if you have multiple 
      input parameters, declare the parameter with the number 
      of parameters in your application, ex. New SqlParameter[4]; */

    public SqlParameter[] SearchValue = new SqlParameter[1];

    protected void RunReportButton_Click(object sender, EventArgs e)
    {
        //ReportViewer1.Visible is set to false in design mode

        ReportViewer1.Visible = true;
        SqlConnection thisConnection = new SqlConnection(thisConnectionString);
        System.Data.DataSet thisDataSet = new System.Data.DataSet();       
        SearchValue[0] = new SqlParameter("@CategoryName", 
                         DropDownList1.SelectedValue);

        /* Put the stored procedure result into a dataset */
        thisDataSet = SqlHelper.ExecuteDataset(thisConnection, 
                      "ShowProductByCategory", SearchValue);

        /*or   thisDataSet = SqlHelper.ExecuteDataset(thisConnection, 
               "ShowProductByCategory", dropdownlist1.selectedvalue); 
               if you only have 1 input parameter  */

        /* Associate thisDataSet  (now loaded with the stored 
           procedure result) with the  ReportViewer datasource */
        ReportDataSource datasource = new 
          ReportDataSource("DataSetProducts_ShowProductByCategory", 
          thisDataSet.Tables[0]);

        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.LocalReport.DataSources.Add(datasource);
        if (thisDataSet.Tables[0].Rows.Count == 0)
        {
            lblMessage.Text = "Sorry, no products under this category!";
        }

        ReportViewer1.LocalReport.Refresh();
    }
}


Edit TR: Two things :

  • Please use <pre> tags to make your code easier to read (use the 'code block' button on the toolbar)
  • Please be more specific. What don't you like about the code? What have you tried?
Posted
Updated 21-Apr-10 3:51am
v2

ramyaaksh wrote:
here the error is showing near sqlhelper.

What is SqlHelper? Dont see anything defined in your code.

ramyaaksh wrote:
i need some other alternative code.

You need to create a SqlCommand, open connection, add query and parameteres to that command, execute it!
 
Share this answer
 
Following is code done by me to add report viewer control dynamically to display reports

C++
ReportViewer ReportViewer1 = new ReportViewer();
                if (ddlListofReports.SelectedValue != "11")
                {

                    ReportViewer1.ProcessingMode = ProcessingMode.Local;
                    ReportViewer1.ID = "ReportViewer1";
                    // Set default values
                    ReportViewer1.Font.Bold = false;
                    ReportViewer1.Font.Name = "Arial";
                    //ReportViewer1.ShowExportControls = false;
                    ReportViewer1.ShowBackButton = false;
                    ReportViewer1.SizeToReportContent = true;
                    ReportViewer1.BackColor = System.Drawing.Color.WhiteSmoke;
                    // Reset the control collection position
                    //coll.AddAt(oldIndex, ReportViewer1);
                    //coll.Remove(oldViewer);
                    ReportViewer1.LocalReport.DataSources.Clear();
                }
                #endregion reportviewer setting





C++
#region CampaignProgressReport
                if (ddlListofReports.SelectedValue == "0")
                {
                    _reportID = "CampaignProgressReport";
                    List<SnapshotReport> List = new SnapshotReport().GetCustomersForCountry(this.DropDownList1.SelectedValue, this.DropDownList2.SelectedValue, dcfromdate.Text);
                    ReportViewer1.LocalReport.ReportPath = "Admin\\ReportDesigns\\" + _reportID + ".rdlc";
                    if (List != null)
                    {
                        if (List.Count > 0)
                        {
                            ReportParameter ServiceName = new ReportParameter("ServiceName", this.DropDownList1.SelectedItem.Text);
                            ReportParameter[] p = { ServiceName };
                            ReportViewer1.LocalReport.SetParameters(p);
                            ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("SnapshotReport1", List));
                            isnull = false;
                        }
                    }
                }
                #endregion CampaignProgressReport




MIDL
divRptView.Controls.Add(ReportViewer1);
                       ReportViewer1.Height = 290 + (25 * 10);
                       ReportViewer1.Width = Unit.Percentage(91);
                       ReportViewer1.ShowRefreshButton = false;
                       ReportViewer1.Visible = true;
                       ReportViewer1.ShowPrintButton = true;
                       ReportViewer1.SizeToReportContent = true;
                       ReportViewer1.LocalReport.Refresh();



if you have any query feel free to contact
 
Share this answer
 
Could you please explain your question. You can find similar problems already solved try Google :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900