Quantcast
Channel: SQL Server Reporting Services
Viewing all articles
Browse latest Browse all 1418

Typed dataset issue when using in the code for RDLC

$
0
0

Hi,

I am using a typed dataset with which I will produce a report. But unfortunately, I have issues with its recognition on the server side, When I write the code, I get a compile time error "Cannot convert from 'Projections.Reports.SpecialOrder_AllLocations' to 'System.Data.Daaset' ". The name of my typed dataset is SpecialOrder_AllLocations. Please check my code and help me why I am unable to do this.

 private SpecialOrder_AllLocations GetData(string query)
        {
            try
            {

                string conString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
                SqlCommand cmd = new SqlCommand(query);
                using (SqlConnection con = new SqlConnection(conString))
                {
                    using (SqlDataAdapter sda = new SqlDataAdapter())
                    {
                        cmd.Connection = con;

                        sda.SelectCommand = cmd;
                        using (SpecialOrder_AllLocations dsCustomers = new SpecialOrder_AllLocations())
                        {
                            sda.Fill(dsCustomers, "RptSpecialOrder_AllLoc");
                            return dsCustomers;
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                lblMessage.CssClass = "alert alert-warning";
                lblMessage.Text = "Msg 104: Please choose a valid date range";
                return null;
            }
        }
        protected void btnCreateReport_Click(object sender, EventArgs e)
        {
            try
            {
                ReportViewer1.Visible = true;

                string FromDate = txtFromDate.Text;
                string ToDate = txtToDate.Text;

                ReportParameter rp1 = new ReportParameter("prmFromDate", txtFromDate.Text.ToString());
                ReportParameter rp2 = new ReportParameter("prmToDate", txtToDate.Text.ToString());

                //string query = "select CAST(Dump_Date As Date) As Date,Dump_Num As Dump_Number,ItemID as Item_ID,ItemName As Item_Description,Qty,Cost,cast(SUM(CAST(Qty as decimal(14,4))*cast(Cost as decimal(14,4))) as decimal(14,2)) As Total from IC_Dump_T where SiteID = '" + FromSite + "' and Dump_Date between '" + FromDate + "' and '" + ToDate + "' group by Dump_Date,ItemID,Dump_Num,ItemName,Qty,Cost order by ItemID asc,Date desc";
                string query = "select CONVERT(varchar(19), Dump_Date, 101) as Date,Dump_Num As Dump_Number,ItemID as Item_ID,ItemName As Item_Description,Qty,Cost,cast(SUM(CAST(Qty as decimal(14,4))*cast(Cost as decimal(14,4))) as decimal(14,2)) As Total from IC_Dump_T where SiteID = '" + FromSite + "' and Dump_Date between '" + FromDate + "' and '" + ToDate + "' group by Dump_Date,ItemID,Dump_Num,ItemName,Qty,Cost order by ItemID asc,convert(datetime, Dump_Date, 101) ASC";
                ReportViewer1.ProcessingMode = ProcessingMode.Local;
                ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/RptSpecialOrder_AllLocations.rdlc");
                SpecialOrder_AllLocations dsdump = GetData(query);
                ReportDataSource datasource = new ReportDataSource("SpecialOrder_AllLocations", dsdump.Tables[0]);
                ReportViewer1.LocalReport.DataSources.Clear();
                ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp1, rp2 });
                ReportViewer1.LocalReport.DataSources.Add(datasource);
            }
            catch
            {
                lblMessage.CssClass = "alert alert-warning";
                lblMessage.Text = "Msg 014: Please choose a valid date range";
            }
        }

issue 2 is also a compilation one. In the line,

 ReportDataSource datasource = new ReportDataSource("SpecialOrder_AllLocations", dsdump.Tables[0]);

I get a compile time error at Tables[0] saying "SpecialOrder_AllLocations does not contain a definition for tables and extension method Tables accepting a first argument of type SpecialOrder_AllLocations  could be found. (Are you missing any using directive or an assembly reference)". What sort of modifications should I do in my code to make this work. Please help me in this.

Regards,

Deepak


Viewing all articles
Browse latest Browse all 1418

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>