Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How To Pass Parameters To A Crystal Report Programmatically

How To Pass Parameters To A Crystal Report Programmatically

Scheduled Pinned Locked Moved C#
tutorialquestionsharepointdatabasehelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fahad Ali
    wrote on last edited by
    #1

    I am making a report in which i have to show that how many purchase orders were issued to which supplier.So i am taking input from the user, the id of the supplier.That id belongs to a certain supplier.i am having problems with the parameters, how do i send the Supplier_Id to the crystal report so that i can view the data.This code given is working fine i am using command in which i am giving hard coded values like where Supplier_Id=2 with the query But what my problem is, that how can i get the value from Combo box into the command object.The report is being displayed with this code but it's hard coded like where Supplier_id=2.Now tell me what should i do in order to take values dynamically into the command object.Pls give me a detailed description and if i am using the wrong technique guide me,which technique should i use as i am new to C.R.Thanks. try { int Supplier_Id = Convert.ToInt32(Supp_Id_C.Text); string sp="sp_P_S_Rpt"; SqlConnection conn = Class_Connection.Make_Conn(); SqlCommand command = new SqlCommand(sp, conn); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@Supplier_Id", SqlDbType.Int).Value = Supplier_Id; SqlDataAdapter adapter = new SqlDataAdapter(command); DataSet ds = new DataSet(); ds.Clear(); adapter.Fill(ds, "P_S_Rpt"); dataGrid1.DataSource = ds; //dataGrid1.DataMember = "P_S_Rpt"; CrystalDecisions.CrystalReports.Engine.ReportDocument rptDoc = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); //rptDoc.FilePath = "MyTaskReport1.rpt"; //rptDoc.SetDatabaseLogon("sa","sa","CDMA","Final_Project1_e"); rptDoc.Load("CrystalReport1.rpt"); rptDoc.SetDatabaseLogon("sa","sa","CDMA","Final_Project1_e"); rptDoc.SetDataSource(ds); //frmReport objfrmReport = new frmReport(); // objfrmReport.crViewer1.ReportSource = rptDoc; // objfrmReport.crViewer1.RefreshReport(); // objfrmReport.Show(); //rptDoc.Refresh(); crystalReportViewer1.ReportSource = rptDoc; crystalReportViewer1.RefreshReport(); //crystalReportViewer1.Refresh(); //crystalReportViewer1.Show(); } catch(Exception ee) { MessageBox.Show(ee.Message); } Fahad

    D 1 Reply Last reply
    0
    • F Fahad Ali

      I am making a report in which i have to show that how many purchase orders were issued to which supplier.So i am taking input from the user, the id of the supplier.That id belongs to a certain supplier.i am having problems with the parameters, how do i send the Supplier_Id to the crystal report so that i can view the data.This code given is working fine i am using command in which i am giving hard coded values like where Supplier_Id=2 with the query But what my problem is, that how can i get the value from Combo box into the command object.The report is being displayed with this code but it's hard coded like where Supplier_id=2.Now tell me what should i do in order to take values dynamically into the command object.Pls give me a detailed description and if i am using the wrong technique guide me,which technique should i use as i am new to C.R.Thanks. try { int Supplier_Id = Convert.ToInt32(Supp_Id_C.Text); string sp="sp_P_S_Rpt"; SqlConnection conn = Class_Connection.Make_Conn(); SqlCommand command = new SqlCommand(sp, conn); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@Supplier_Id", SqlDbType.Int).Value = Supplier_Id; SqlDataAdapter adapter = new SqlDataAdapter(command); DataSet ds = new DataSet(); ds.Clear(); adapter.Fill(ds, "P_S_Rpt"); dataGrid1.DataSource = ds; //dataGrid1.DataMember = "P_S_Rpt"; CrystalDecisions.CrystalReports.Engine.ReportDocument rptDoc = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); //rptDoc.FilePath = "MyTaskReport1.rpt"; //rptDoc.SetDatabaseLogon("sa","sa","CDMA","Final_Project1_e"); rptDoc.Load("CrystalReport1.rpt"); rptDoc.SetDatabaseLogon("sa","sa","CDMA","Final_Project1_e"); rptDoc.SetDataSource(ds); //frmReport objfrmReport = new frmReport(); // objfrmReport.crViewer1.ReportSource = rptDoc; // objfrmReport.crViewer1.RefreshReport(); // objfrmReport.Show(); //rptDoc.Refresh(); crystalReportViewer1.ReportSource = rptDoc; crystalReportViewer1.RefreshReport(); //crystalReportViewer1.Refresh(); //crystalReportViewer1.Show(); } catch(Exception ee) { MessageBox.Show(ee.Message); } Fahad

      D Offline
      D Offline
      DrKlund
      wrote on last edited by
      #2

      Hi, I hope you ca use this. // Create parameter objects ParameterFields myParams = new ParameterFields(); // Tilføj InternalNumber myParams.Add(MakeParam("@Customer_Id", ReportBackup_Ids)); myParams.Add(MakeParam("@CustomerName", "")); myParams.Add(MakeParam("@CustomerAddr1", "")); myParams.Add(MakeParam("@CustomerAddr2", "")); myParams.Add(MakeParam("@CustomerAddr3", "")); myParams.Add(MakeParam("@CustomerZip", "")); myParams.Add(MakeParam("@CustomerCity", "")); myParams.Add(MakeParam("@CustomerCountry", "")); myParams.Add(MakeParam("@CustomerPhone", "")); // Assign the params collection to the report viewer crystalReportViewer1.ParameterFieldInfo = myParams; Karsten Lundsgaard

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups