How To Pass Parameters To A Crystal Report Programmatically
-
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
-
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
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