Click here to Skip to main content
12,394,788 members (67,679 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# C#4.0
hi in my winform application two textboxes and one button is der
when i enter value i mean two dates start and and date in two textboxes after hitting button i want to display records in crystal report..

i tried code but not redirecting to crystal report..

can any one suggest me?

thank u.
Posted 10-Jul-12 20:58pm
ythisbug2.1K
Updated 10-Jul-12 23:16pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Dear

Create a dataset in your solution and add a table and create the columns as you need inside the data set table.
for eg: Your Datset is MyDataSet and I add a table called table1.
Dim rptviewer As New frmrReportViewer
        Dim rptclass As ReportClass
        Try
            Dim query As String
            Dataset DS = New MyDataSet
            Dim dt As DataTable
 
            Dim row As DataRow
            rptclass = New rptCustomerReport      ' My Report Class (crystal report)

         
 
            DS.Clear() 
            dt = DS.Tables("CUSTOMER")     ' Customer is My Table Name
            row = dt.NewRow
            row("DATE1") ="Your First Value"
            row("DATE2") = "Your second Value"
            dt.Rows.Add(row)   
           
            rptclass.SetDataSource(DS)  'Set the Datset to the report
            rptviewer.CrystalReportViewer1.ReportSource = rptclass  ' Show the report by using a Reportviwert control
            rptviewer.ShowDialog()
        Catch ex As Exception
            rptclass.SetDataSource(DS)
            rptviewer.CrystalReportViewer1.ReportSource = rptclass
            rptviewer.ShowDialog()
  Permalink  
v2
Comments
ythisbug 11-Jul-12 4:31am
   
thanks i want c# code..this vb know
Sandeep Mewara 11-Jul-12 5:17am
   
Always format your code with PRE tags. It makes it readable.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Try:
ReportDocument cryRpt = new ReportDocument();
 
cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\\CrystalReport1.rpt");
ParameterFieldDefinitions crParameterFieldDefinitions;
ParameterFieldDefinition crParameterFieldDefinition;
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
 
crParameterDiscreteValue.Value = TextBox1.Text;
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions.Item["Customername"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
 
crParameterValues.Clear();
 
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
 
CrystalReportViewer1.ReportSource = cryRpt;
CrystalReportViewer1.Refresh();
  Permalink  
Comments
ythisbug 11-Jul-12 6:05am
   
thanks

am getting error for this line..
invalid index...


crParameterFieldDefinition = crParameterFieldDefinitions["tblPurchase"];
Sandeep Mewara 11-Jul-12 7:02am
   
If you have it defined as a parameter in crystal report it should be good.
ythisbug 11-Jul-12 7:11am
   
ya thanks
ythisbug 11-Jul-12 7:16am
   
i removed parameter now working but..i want report from within two textbox..for that any idea..
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

private void button1_Click(object sender, EventArgs e)
      {
        SqlConnection con = new SqlConnection(@"Data Source=ythisbug;Initial Catalog=ythisbug; User ID=sa; Password=******;");
 
           con.Open();
          
          try
          {
 
              string StartDate = textBox1.Text;
              string EndDate = textBox2.Text;
              SqlCommand com = new SqlCommand();
                     SqlDataAdapter sqlda;
                             DataSet ds;
                     string str;
                   
                     com.CommandType = CommandType.StoredProcedure;
                     com.CommandText = "usp_GetDateSales";
                                   
                     com.Connection = con;
 
                     SqlParameter pStartDate = new SqlParameter("@STARTDATE", SqlDbType.DateTime);
                     pStartDate.Value = StartDate;
                     com.Parameters.Add(pStartDate);
                     SqlParameter pEndDate = new SqlParameter("@ENDDATE", SqlDbType.DateTime);
                     pEndDate.Value = EndDate;
                     com.Parameters.Add(pEndDate);
 
                     DataTable dt = new DataTable();
                     SqlDataAdapter da = new SqlDataAdapter(com);
                     da.Fill(dt);
 
                     com.Dispose();
                     con.Close();
 
                    sqlda = new SqlDataAdapter(com);
                    ds = new DataSet();
                    sqlda.Fill(ds, "tblPurchase");
                    con.Close();
                    ReportDocument r1 = new ReportDocument();
                    r1.Load(@"C:\Users\admin\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Reports\CrystalReport1.rpt");
 
                    r1.SetDataSource(ds);
                    crystalReportViewer1.ReportSource = r1;
                    crystalReportViewer1.Refresh();
          }
          catch(Exception ex)
          {
              
              
          }
          finally
          {
              con.Close();
          }
              
 
           }
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

what is the code in this stored procedure (usp_GetDateSales).
plz post!!!
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160721.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100