none
Reportviewer RRS feed

  • Question

  • mySQL;

    SELECT TARIH, SAAT, ACIKLAMA, ISLEMTURU, KOY_MAH, ADA, PARSEL, BIRIMFIYAT,
           (SELECT ISNULL(SUM(OdemeNakit), 0) AS Odenen FROM OdemeBase AS o
            WHERE (m.workID = workID)) AS Odenen
    FROM  MulkiyetBase AS m WHERE (mustID = @perID)
    GROUP BY TARIH, SAAT, ACIKLAMA, ISLEMTURU, KOY_MAH, ADA, PARSEL, BIRIMFIYAT, workID

    When I add a Reportviewer e section;

    When I view the report section;

    public string strReport = "rdlcmulkiyetinfo";
            void Window_Loaded(object sender, RoutedEventArgs e)
            {
                var ds = new ReportsDetails();
                var rptDataSource = new ReportDataSource("dsMulkiyet", ds.Tables["MulkiyetBase"]);
                const string rdlcAdd = @"CCTrackingProgram.";
                switch (strReport)
                {
                    case "rdlcmulkiyetinfo":
                        var da = new CCTrackingProgram.ReportsDetailsTableAdapters.MulkiyetBaseTableAdapter();
                        var PerID = System.Windows.Application.Current.Windows.OfType<wpfOdemeTablosu>().FirstOrDefault();
                        rptTahsilatDetailsViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SubReportDoldur);
                        rptDataSource.Value = da.GetDataByMulkiyetSorgula(PerID.must_ID);//wpfOdemeTablosundan ID al;
                        break;
                    default:
                        break;
                }
                this.rptTahsilatDetailsViewer.LocalReport.ReportEmbeddedResource = rdlcAdd + strReport + ".rdlc";
                this.rptTahsilatDetailsViewer.LocalReport.DataSources.Clear();
                this.rptTahsilatDetailsViewer.LocalReport.DataSources.Add(rptDataSource);
                this.rptTahsilatDetailsViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);

    reportviewer is pulling data from the report dataset 2, I created and would like to show you;

    I received error;

    An unhandled exception of type 'System.Data.ConstraintException' occurred in System.Data.dll


    • Moved by Caillen Monday, September 29, 2014 1:56 AM
    Sunday, September 28, 2014 5:24 AM

Answers

All replies

  • Add an exception handler to the code and post results of the Stack Trace.

           public string strReport = "rdlcmulkiyetinfo";
            void Window_Loaded(object sender, RoutedEventArgs e)
            {
                try
                {
                    var ds = new ReportsDetails();
                    var rptDataSource = new ReportDataSource("dsMulkiyet", ds.Tables["MulkiyetBase"]);
                    const string rdlcAdd = @"CCTrackingProgram.";
                    switch (strReport)
                    {
                        case "rdlcmulkiyetinfo":
                            var da = new CCTrackingProgram.ReportsDetailsTableAdapters.MulkiyetBaseTableAdapter();
                            var PerID = System.Windows.Application.Current.Windows.OfType<wpfOdemeTablosu>().FirstOrDefault();
                            rptTahsilatDetailsViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SubReportDoldur);
                            rptDataSource.Value = da.GetDataByMulkiyetSorgula(PerID.must_ID);//wpfOdemeTablosundan ID al;
                            break;
                        default:
                            break;
                    }
                    this.rptTahsilatDetailsViewer.LocalReport.ReportEmbeddedResource = rdlcAdd + strReport + ".rdlc";
                    this.rptTahsilatDetailsViewer.LocalReport.DataSources.Clear();
                    this.rptTahsilatDetailsViewer.LocalReport.DataSources.Add(rptDataSource);
                    this.rptTahsilatDetailsViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error : {0}", e.Message);
                    Console.WriteLine("Stack Trace : {0}", e.StackTrace);
    
                }
            }


    jdweng

    Sunday, September 28, 2014 7:01 AM
  • What line is giving the error?  It looks like the columns in the DataTable and the query columns are inconsistent.  At least one data type doesn't match.  There is a BOOLEAN value that isn't matching.  It may be that you have the Boolean value defined in one place as a STRING "True" or "False" instead of True or False.


    jdweng

    Sunday, September 28, 2014 8:09 AM
  • Hi Kenan,

    I'm moving your question to Visual Studio Report Controls forum because Visual C# forum is not the right forum for your question.

    Thanks for your understanding.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, September 29, 2014 1:59 AM
  • I'm waiting for your help ; :(
    Wednesday, October 1, 2014 3:45 PM
  • Add a test for null.  If PerID is null then you can use the property PerID.must_ID.

                            var da = new CCTrackingProgram.ReportsDetailsTableAdapters.MulkiyetBaseTableAdapter();
                            var PerID = System.Windows.Application.Current.Windows.OfType<wpfOdemeTablosu>().FirstOrDefault();
                            if(PerID != null)
                            {
                               rptTahsilatDetailsViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SubReportDoldur);
                               rptDataSource.Value = da.GetDataByMulkiyetSorgula(PerID.must_ID);//wpfOdemeTablosundan ID al;
                            }


    jdweng

    Thursday, October 2, 2014 6:56 AM
  • Adding "Using" statements isn't bad, it just doesn't tell you when a query is null.  The using statement just jumps out of the using blocks of the code without reporting if any error actually occurred.  You event handler also doesn't set any flags if errors occurred so the main thread of the code know if an error occurred.  This makes debugging the code harder.

    The best way of debugging the code is to add two break points by clicking on the following lines and then press F9.

    1) using (SqlConnection conn = new SqlConnection(strconnection.strConn))
    2) Int64 perlID = Convert.ToInt64(e.Paramters[0].Values[0];

    The run code normally until a break point is reached.  Then step through the code using F11 seeing if the code jumps out of any of the using blocks. 

    When you get to the 2nd break point above highlight with mouse the "e" in the parameter list. Then Right click the "e" and select "Add to Watch". Repeat with "sender". Then verify the "e" and "sender" properties are valid.

    I think in the event handler you need to use "sender". I like doing the following in an event hander

    var abc = sender as xyz // where xyz is the type I get from the WATCH item. The watch will show property value and types. The xyz is the type of the sender.

    My best guess right now there is something wrong with the way you are using e.Parameters in the event handler.


    jdweng


    Tuesday, October 7, 2014 10:43 PM
  •     void SubreportProcessingEvent(object sender, SubreportProcessingEventArgs e)
        {
            SqlDataReader dr;
            DataSet ds = new CustomerBaseDataSet();
            using (SqlConnection conn = new SqlConnection(strconnection.strConn))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    try
                    {
                        conn.Open();
                        cmd.CommandType = CommandType.Text;
                        cmd.Connection = conn;
                        cmd.CommandText = @"Select * From OdemeBase Where OdemeNakitID=@customerID AND workID=@workID;";
                        cmd.Parameters.Add(new SqlParameter("@customerID",Convert.ToInt32(e.Parameters["perID"].Values[0])));
                        cmd.Parameters.Add(new SqlParameter("@workID",Convert.ToInt32(e.Parameters["workID"].Values[0])));
                        dr = cmd.ExecuteReader();
                        ds.Tables[0].Load(dr);
                        dr.Close();
                        conn.Close();
                        e.DataSources.Add(new ReportDataSource("dsOdeme", ds.Tables[0]));
                    }
                    catch (SqlException excp)
                    {
                        System.Windows.Forms.MessageBox.Show(excp.Message);
                    }
                    finally
                    {
                        if (conn.State == ConnectionState.Open)
                        {
                            conn.Close();
                        }
                    }
                }
            }
        }

    I'm viewing the main report; but isn't part of the subreport;
    Wednesday, October 8, 2014 8:37 AM
  • Did yo udo like I suggested and add the break point into the SubReportProcessingEvent.  The sender should match the object in the line that registered the event below.  So SubReportDoldur is the sender

                          rptTahsilatDetailsViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SubReportDoldur);

    So you should have a line like this

    void SubreportProcessingEvent(object sender, SubreportProcessingEventArgs e)
       
    {
                var report = sender as xyz; //where xyz is the type of SubReportDoldur   


     


    jdweng

    Wednesday, October 8, 2014 10:40 AM
  • Hi Joel;

    only works in the query;

     void Subreport(object sender,SubreportProcessingEventArgs e)
            {
             int pID=Convert.ToInt32(e.Parameters[0].Values[0].ToString());
             //int wID = Convert.ToInt32(e.Parameters[1].Values[0].ToString());
             SqlDataReader dr;
             DataSet ds = new OdemeDataSet();
             using (SqlConnection conn = new SqlConnection(ConnectionDb.baglanti))
             {
                 using (SqlCommand cmd = new SqlCommand())
                 {
                     try
                     {
                         conn.Open();
                         cmd.CommandType = CommandType.Text;
                         cmd.Connection = conn;
                         cmd.CommandText = @"Select * From OdemeBase Where OdemeNakitID=@customerID;";// AND workID=@workID;";
                         cmd.Parameters.Add(new SqlParameter("@customerID",pID));
                         //cmd.Parameters.Add(new SqlParameter("@workID",wID));
                         dr = cmd.ExecuteReader();
                         ds.Tables[0].Load(dr);
                         dr.Close();
                         conn.Close();
                         e.DataSources.Add(new ReportDataSource("dsOdeme", ds.Tables[0]));
                     }
                     catch (SqlException excp)
                     {
                         System.Windows.Forms.MessageBox.Show(excp.Message);
                     }
                     finally
                     {
                         if (conn.State == ConnectionState.Open)
                         {
                             conn.Close();
                         }
                     }
                 }
             }
           }
    If I can connect my computer with teamviewer ID please?



    • Edited by Kenan YILMAZ Wednesday, October 8, 2014 11:25 AM
    Wednesday, October 8, 2014 11:21 AM
  • You have the following line in the wrong place.  You need to put the line after the subreport is added.  The line below is registering the event and you may get events without the subreport.

                        rptTahsilatDetailsViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SubReportDoldur);

    You need to register the event after the subreport is added.  Either that or ignore in the event handler events that don't include the subreport.  You are probably get the event more than once (before and after the subreport is added).  The event handler needs to know when the subreport is fully added.


    jdweng

    Wednesday, October 8, 2014 11:57 AM
  • hi Joel;

    Here's all the code I wrote;

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using Microsoft.Reporting.WinForms;
    using System.Data;
    using System.Data.SqlClient;
    namespace SubreportDateils
    {
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
                MainReport(12,967219238619887872);
            }
            void MainReport(Int64 custID, Int64 jobID)
            {
                SqlDataReader drReport;
                DataSet dsReport = new MulkiyetDataSet();
                using (SqlConnection conn = new SqlConnection(ConnectionDb.baglanti))
                {
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        try
                        {
                            conn.Open();
                            cmd.CommandType = CommandType.Text;
                            cmd.Connection = conn;
                            cmd.CommandText = @"Select * From MulkiyetBase Where mustID=@mustID AND workID=@workID;";
                            cmd.Parameters.Add(new SqlParameter("@mustID",(Int64)custID));
                            cmd.Parameters.Add(new SqlParameter("@workID",(Int64)jobID));
                            drReport = cmd.ExecuteReader();
                            dsReport.Tables[0].Load(drReport);
                            drReport.Close();
                            conn.Close();
                            rdlcReports.LocalReport.DataSources.Clear();
                            rdlcReports.LocalReport.ReportEmbeddedResource = "SubreportDateils.myRapor.MainMulkiyet.rdlc";
                            rdlcReports.LocalReport.DataSources.Clear();
                            rdlcReports.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(Subreport);
                            rdlcReports.LocalReport.DataSources.Add(new ReportDataSource("dsMulkiyet", dsReport.Tables[0]));
                            rdlcReports.DocumentMapCollapsed = true;
                            //***************************************************************************************************
                            rdlcReports.RefreshReport();
                            rdlcReports.SetDisplayMode(DisplayMode.PrintLayout);
                            rdlcReports.ZoomMode = ZoomMode.PageWidth;
                            rdlcReports.ZoomPercent = 100;
                            rdlcReports.RefreshReport();
                        }
                        catch (SqlException excp)
                        {
                            System.Windows.Forms.MessageBox.Show(excp.Message);
                        }
                        finally
                        {
                            if (conn.State == ConnectionState.Open)
                            {
                                conn.Close();
    
                            }
                        }
                    }
                }
            }
            void Subreport(object sender,SubreportProcessingEventArgs e)
            {
             var pID=Convert.ToInt64(e.Parameters["perID"].Values[0].ToString());
             MessageBox.Show("" + pID);
             //int wID = Convert.ToInt32(e.Parameters[1].Values[0].ToString());
             SqlDataReader dr;
             DataSet ds = new OdemeDataSet();
             using (SqlConnection conn = new SqlConnection(ConnectionDb.baglanti))
             {
                 using (SqlCommand cmd = new SqlCommand())
                 {
                     try
                     {
                         conn.Open();
                         cmd.CommandType = CommandType.Text;
                         cmd.Connection = conn;
                         cmd.CommandText = @"Select * From OdemeBase Where OdemeNakitID=@customerID";// AND workID=@workID;";
                         cmd.Parameters.Add(new SqlParameter("@customerID",pID));
                         //cmd.Parameters.Add(new SqlParameter("@workID",wID));
                         dr = cmd.ExecuteReader();
                         ds.Tables[0].Load(dr);
                         dr.Close();
                         conn.Close();
                         e.DataSources.Add(new ReportDataSource("dsOdeme", ds.Tables[0]));
                     }
                     catch (SqlException excp)
                     {
                         System.Windows.Forms.MessageBox.Show(excp.Message);
                     }
                     finally
                     {
                         if (conn.State == ConnectionState.Open)
                         {
                             conn.Close();
                         }
                     }
                 }
             }
           }
    
    
    
        }
    }
    
    You can help to make things right?

    Wednesday, October 8, 2014 12:11 PM
  • I don't have the class  rdlcReports

    jdweng

    Wednesday, October 8, 2014 12:57 PM
  • happy ending;

    • Marked as answer by Kenan YILMAZ Wednesday, October 8, 2014 11:47 PM
    Wednesday, October 8, 2014 11:46 PM