Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Updated 10-Jul-12 23:16pm
v2

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.
VB
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()
 
Share this answer
 
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.
Try:
C#
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();
 
Share this answer
 
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..
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();
          }
              

           }
 
Share this answer
 
what is the code in this stored procedure (usp_GetDateSales).
plz post!!!
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900