locked
Crystal Report Using C# RRS feed

  • Question

  • Actually I am retrieving data from database and passing parameter to report. But I am getting problem where only one record  is showing. Not retrieving all data. So how can I use for loop for reading database. Can anyone help me.

    An example : I am using TABID and Cluster where two clusters in one TABID. Only one showing.

    • Moved by Kristin Xie Wednesday, April 1, 2015 2:21 AM
    Wednesday, March 25, 2015 11:41 AM

Answers

  • Hi PrasantaBangla,

    >>An example : I am using TABID and Cluster where two clusters in one TABID. Only one showing.

    I would like to know what do you mean by TABID and Cluster where two clusters in one TABID?

    In addition, based on your title, it seems  related to Crystal Report,

    For questions related to Crystal Report should be asked in Crystal Report forum.

    http://forums.sdn.sap.com/forum.jspa?forumID=313 

    Best regards,

    Kristin


    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.

    • Proposed as answer by Just Karl Wednesday, April 1, 2015 8:16 PM
    • Marked as answer by Just Karl Wednesday, April 8, 2015 9:21 PM
    Thursday, March 26, 2015 6:17 AM

All replies

  • First check if your Datasource is returning the whole data you want based on the parameter you're passing, you can do this either by debugging through the code or executing the related query. Second what type of report are you using and can you send a screen shot of your report desinger view?

    Fouad Roumieh


    Thursday, March 26, 2015 5:53 AM
  • Hi PrasantaBangla,

    >>An example : I am using TABID and Cluster where two clusters in one TABID. Only one showing.

    I would like to know what do you mean by TABID and Cluster where two clusters in one TABID?

    In addition, based on your title, it seems  related to Crystal Report,

    For questions related to Crystal Report should be asked in Crystal Report forum.

    http://forums.sdn.sap.com/forum.jspa?forumID=313 

    Best regards,

    Kristin


    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.

    • Proposed as answer by Just Karl Wednesday, April 1, 2015 8:16 PM
    • Marked as answer by Just Karl Wednesday, April 8, 2015 9:21 PM
    Thursday, March 26, 2015 6:17 AM
  • I am using below those code. Record showing only last. But two records are available. Please help me what is the problem

    private void btnShow_Click(object sender, EventArgs e)
            {
                SqlConnection Conn = new SqlConnection(connStr);

                try
                {

                        Conn.Open();
                        string StringREP = "select TABID, Name from TEMPREP order by TABID";
                        SqlCommand CommandTAB = new SqlCommand(StringREP, Conn);
                        SqlDataReader rd = CommandTAB.ExecuteReader();

                        if (rd.FieldCount > 0)
                        {
                            while (rd.Read())
                            {
                                TABID = rd[0].ToString();
                                Name = rd[1].ToString();

                                ReportShow();

                           }

                       }

               }

                catch (Exception Ex)
                {
                    MessageBox.Show(Ex.Message);
                }
                finally
                {
                    Conn.Close();
                }
            }

    //////////PASSING PARAMETER///////////////

    private void ReportShow()
            {
                SqlConnection Conn = new SqlConnection(connStr);
                try
                {
                    Conn.Open();
                    string StringREP = "select TABID, Name from TEMPREP order by TABID";
                    SqlCommand CommandREP = new SqlCommand(StringREP, Conn);
                    SqlDataReader rd = CommandREP.ExecuteReader();

                    ReportDocument reportDocument = new ReportDocument();
                    ParameterFields paramFields = new ParameterFields();

                    ParameterField paramField = new ParameterField();
                    ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();

                    if (rd.FieldCount > 0)
                    {
                        while (rd.Read())
                        {
                            paramField = new ParameterField(); // <-- Date Filter Report Selection Start Date
                            paramDiscreteValue = new ParameterDiscreteValue();
                            paramField.Name = "@TABID";
                            paramDiscreteValue.Value = TABID;
                            paramField.CurrentValues.Add(paramDiscreteValue);
                            paramFields.Add(paramField);

                            paramField = new ParameterField(); // <-- Date Filter Report Selection End Date
                            paramDiscreteValue = new ParameterDiscreteValue();
                            paramField.Name = "@Name";
                            paramDiscreteValue.Value = Name;
                            paramField.CurrentValues.Add(paramDiscreteValue);
                            paramFields.Add(paramField);

                            reportDocument.Load("D:\\crpScvbPer.rpt");

                         }

                        }

                      }

                    }

                    rptPer.ParameterFieldInfo = paramFields;
                    rptPer.ReportSource = reportDocument;
                    rptPer.Visible = true;
                }
                catch (Exception Ex)
                {
                    MessageBox.Show(Ex.Message);
                }
                finally
                {
                    Conn.Close();
                }
            }


    Monday, March 30, 2015 7:04 AM
  • As you can you see below you calling ReportShow form within the while loop, so it will be called twice since you have 2 records then it will show you the last record, also from your code I can't understand what do you want to achieve out of TABID and Name variables, we normally pass the parameter once to the report, could you please explain this?

     while (rd.Read())
                            {
                                TABID = rd[0].ToString();
                                Name = rd[1].ToString();
    //This is a wrong call here
                                ReportShow();
    
                           }


    Fouad Roumieh

    Monday, March 30, 2015 7:24 AM
  • Also here you creating the instance:

    ParameterField paramField = new ParameterField();
                    ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();


    and then you creating it again:

    paramDiscreteValue = new ParameterDiscreteValue();

     paramField = new ParameterField(); 

    so change the first to:

    ParameterField paramField;
                    ParameterDiscreteValue paramDiscreteValue;


    Fouad Roumieh

    Monday, March 30, 2015 7:26 AM
  • Thanks I changed two instances. Actually I used for searching end of records but showing last record. But how I will show all records into report.
    Monday, March 30, 2015 8:19 AM
  • Actually I used for searching end of records but showing last 
    This is not an answer, please explain, before finding the solution we need to understand your problem. Can you post an excel screenshot of how your final report will look like. The logic within you code is still wrong.

    Fouad Roumieh


    Monday, March 30, 2015 8:22 AM
  • Change you code to 
    private void btnShow_Click(object sender, EventArgs e)
            {
               
    
                                ReportShow();
    
                          
               }
    
                catch (Exception Ex)
                {
                    MessageBox.Show(Ex.Message);
                }
                finally
                {
                    Conn.Close();
                }
            }
    
    //////////PASSING PARAMETER///////////////
    
    private void ReportShow()
            {
                SqlConnection Conn = new SqlConnection(connStr);
                try
                {
                    Conn.Open();
                    string StringREP = "select TABID, Name from TEMPREP order by TABID";
                    SqlCommand CommandREP = new SqlCommand(StringREP, Conn);
                    SqlDataReader rd = CommandREP.ExecuteReader();
    
                    ReportDocument reportDocument = new ReportDocument();
                    ParameterFields paramFields = new ParameterFields();
    
                    ParameterField paramField;
                    ParameterDiscreteValue paramDiscreteValue;
    
                    if (rd.FieldCount > 0)
                    {
                        while (rd.Read())
                        {
                            paramField = new ParameterField(); // <-- Date Filter Report Selection Start Date
                            paramDiscreteValue = new ParameterDiscreteValue();
                            paramField.Name = "@TABID";
                            paramDiscreteValue.Value =  rd[0].ToString();
                            paramField.CurrentValues.Add(paramDiscreteValue);
                            paramFields.Add(paramField);
    
                            paramField = new ParameterField(); // <-- Date Filter Report Selection End Date
                            paramDiscreteValue = new ParameterDiscreteValue();
                            paramField.Name = "@Name";
                            paramDiscreteValue.Value =  rd[1].ToString();
                            paramField.CurrentValues.Add(paramDiscreteValue);
                            paramFields.Add(paramField);
    
                            
    
                         }
    
                        }
    
                      }
    
                    }
    		reportDocument.Load("D:\\crpScvbPer.rpt");
                    rptPer.ParameterFieldInfo = paramFields;
                    rptPer.ReportSource = reportDocument;
                    rptPer.Visible = true;
                }
                catch (Exception Ex)
                {
                    MessageBox.Show(Ex.Message);
                }
                finally
                {
                    Conn.Close();
                }
            }


    Fouad Roumieh

    Monday, March 30, 2015 8:30 AM
  • I am entering data through windows form after that I want to display data


    TABID Name
    101 Anis
    102 Baby
    103 Caila
    Monday, March 30, 2015 8:30 AM
  • Thanks for quick response. I applied your code but still only second record is showing. I am not getting. Please help me.

    Monday, March 30, 2015 8:58 AM
  • Can you post a screenshot of your report designer?. Please also see here a sample of creatring a simple cyrstal report using the wizard. Because I don't see the point of using the paramenters field to create record in the report.

    http://www.codeproject.com/Tips/499498/Creating-a-simple-but-useful-Crystal-Report


    Fouad Roumieh

    Monday, March 30, 2015 9:27 AM
  • The parameterfields are not meant to loop over and build the records (at least that's my knowledge about it), it's just one value to pass and print please follow the above link or this one to create your report:

    http://www.codeproject.com/Tips/754037/Bind-Crystal-Reports-with-Dataset-or-Datatable


    Fouad Roumieh

    Monday, March 30, 2015 9:47 AM
  • Monday, March 30, 2015 10:01 AM
  • Thank you, as I said the parameter field are not meant to do what you looking for. It will keep replacing the value with each loop and that's why you getting last values poplulated into these parameters.

    Fouad Roumieh

    Monday, March 30, 2015 10:05 AM
  • Actually My field values are not fixed. It will be changing by date wise. So I didn't include database into crystal report database expert. That's why I am passing parameter value which connected with server. So I will not get any hassle. If I include database through database expert then how I will change database all time.
    Monday, March 30, 2015 10:19 AM
  • Are you talking about changing the database itself or just the connection string? You can change your connection string as long as the table/sql strored procedure used by the report exist.

    Fouad Roumieh

    Monday, March 30, 2015 10:57 AM
  • Hi, PrasantaBangla,

    Please redirect to Crystal Report forum.

    http://forums.sdn.sap.com/forum.jspa?forumID=313 

    Thanks for your understanding.

    Regards,

    Kristin


    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.

    Wednesday, April 1, 2015 2:21 AM