Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 WinForm
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 21:58pm
ythisbug2.1K
Edited 11-Jul-12 0:16am
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 at 11-Jul-12 4:31am
   
thanks i want c# code..this vb know
Sandeep Mewara at 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 at 11-Jul-12 6:05am
   
thanks
 
am getting error for this line..
invalid index...

 
crParameterFieldDefinition = crParameterFieldDefinitions["tblPurchase"];
Sandeep Mewara at 11-Jul-12 7:02am
   
If you have it defined as a parameter in crystal report it should be good.
ythisbug at 11-Jul-12 7:11am
   
ya thanks
ythisbug at 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
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2014
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