locked
Report Viewer 2010 Issue RRS feed

  • Question

  • User-782162750 posted

    Hi,

    I have a sample code that is working on the VS2008 report viewer, and now i need to do the same but using VS2010 and this code isn't working :(

    Code:

    private void Create(string id)
        {
            //a DataSet        
    certificadoDataSetTableAdapters.GetCertificadoTipoEdificioTableAdapter tipoEdificioDS = new certificadoDataSetTableAdapters.GetCertificadoTipoEdificioTableAdapter();        
            
            //datasource
            ReportDataSource tipoEdificioDados = new ReportDataSource("certificadoDataSet_GetCertificadoTipoEdificio", tipoEdificioDS.GetDataCertificadoTipoEdificio(id));
            
            // Setup the report viewer    
            ReportViewer viewer = new ReportViewer();
            viewer.ProcessingMode = ProcessingMode.Local;
            viewer.LocalReport.ReportPath = "Reports/Certificado.rdlc";
            viewer.LocalReport.EnableExternalImages = true;
    
            //add datasource to viewer
            viewer.LocalReport.DataSources.Add(tipoEdificioDados);
        }
    
    
    I'm getting this error:
    Error	6	The call is ambiguous between the following methods or properties: 'Microsoft.Reporting.WebForms.ReportDataSource.ReportDataSource(string, System.Collections.IEnumerable)' and 'Microsoft.Reporting.WebForms.ReportDataSource.ReportDataSource(string, System.Data.DataTable)'
    
    
    Can someone help me on this? I really want to filter the data and load a report on runtime. 
    Tuesday, September 6, 2011 5:46 PM

Answers

  • User101822888 posted

    public class Customer
    {
        public string strCustomerID { set; get; };
        public string strCompanyName{ set; get; };
        public string strContactName{ set; get; };
        public string strCountry{ set; get; };

    }

    public class CustomerManagment
    {
     
        public static List<Customer> GetCustomersById(string customerID)
        {
            SqlConnection cnn = new SqlConnection(
            ConfigurationManager.ConnectionStrings
            ["NorthwindConnectionString"].ConnectionString);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = cnn;
            cmd.CommandText = @"select
            CustomerID,CompanyName,ContactName,Country
            from customers where CustomerID=@CustomerID";
            SqlParameter p = new SqlParameter
            ("@CustomerID", customerID);
            cmd.Parameters.Add(p);
            cnn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            List<Customer> list = new List<Customer>();
            while (reader.Read())
            {
                Customer c = new Customer();
                c.CustomerID = reader.GetString(0);
                c.CompanyName = reader.GetString(1);
                c.ContactName = reader.GetString(2);
                c.Country = reader.GetString(3);
                list.Add(c);
            }
            cnn.Close();
            return list;
        }

    /// then choose the  GetCustomersById as dataset

    in the report viewer page once you add it and select the local report an object datasource will be added automatically ,

    got ot select parameters and add customerID ; you can provide it from control or by writing code as following

    ObjectDataSource1.TypeName = "CustomerManagment";
                ObjectDataSource1.SelectMethod = "GetCustomersById";
                ObjectDataSource1.SelectParameters.Clear();
                ObjectDataSource1.SelectParameters.Add("customerID",  your vlaue);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 7, 2011 8:13 AM