Hi,
I have a datagridview with a number of selected rows. What I need to do is be able to create a crystal report that shows the selected rows. Does anyone know where to start with this cause I'm at a loss, the only solution I could come up with is to create a table in a database and add each row and then create a report from the table, this is not idel.
So if anyone knows where to start please do let me know.
Thanks
Jon

How to create a report from a collection of DataGridView rows
clkdiv
I have a report that pulls data based on what is selected in a combo box. And believe me, I needed major help with this one and it is still pretty confusing but maybe it will at least give you a starting point. Here is my stored procedure (the '''' around the end date, are 4 single quotes not two double quotes)
CREATE PROCEDURE [usp_rptSingleUnitReport]
@EndingDate VarChar(100),
@Where varchar(1000)
--
AS
SET NOCOUNT ON
declare @SQL varchar(8000)
set @sql='
SELECT p.ProjectID, p.ProjectDescription, p.FileNumber, u.UnitDescription, u.Building, u.UnitDescriptionForSort, u.Buyer, ft.TransactionTypeID, ft.TransactionDate, CASE WHEN ft.TransactionTypeId = 1 THEN ft.Amount ELSE 0 END AS CashDeposits,
CASE WHEN ft.TransactionTypeID = 2 THEN ft.amount ELSE 0 END AS CashDisburse, ' + '''' + @EndingDate + '''' + ' as EndingDate
FROM dbo.Project p INNER JOIN
dbo.Unit u ON p.ProjectID = u.ProjectID INNER JOIN
dbo.FinancialTransaction ft ON fa.FinancialAccountID = ft.FinancialAccountID
WHERE ft.UnitID in (' + @Where + ') AND ft.TransactionDate<= ' + '''' + @EndingDate + ''''
exec (@SQL)
GO
And this is to pass the paramater
if (objReports.CurrentReportId==28) //Single Unit Report{
System.Data.SqlClient.SqlParameter[] par =
new System.Data.SqlClient.SqlParameter[2]; int size = 0;par[size] =
new System.Data.SqlClient.SqlParameter("EndingDate", SqlDbType.DateTime);par[size].Value =
this.dtEndDate.Text;size++;
string selectedRows =""; foreach(UltraGridRow dr in dgUnits.Rows){
if(dr.Selected ){
selectedRows = dr.Cells[UnitDataTable.UnitIDColumnName].Value.ToString()+ "," + selectedRows ;
}
}
char[] MyChar = {','}; string NewString = selectedRows.TrimEnd(MyChar);Console.WriteLine(NewString);
par[size] =
new System.Data.SqlClient.SqlParameter("Where", SqlDbType.VarChar);par[size].Value =(NewString);
size++;
DataSet ds = objReports.RunReport("usp_rptSingleUnitReport", par);
ReportViewer rv =
new ReportViewer(ds, "rptSingleUnit.rpt");rv.Show();
}
Bhupathi Venkatesh
First step is if you know what the schema (columns and data type of the data that will be used) then create a xsd file and create the report off of that. At runtime you can pass a dataset object to the report. You can modify your dataset that is used to pass the data to the datagridview to only contain the rows that are selected.
ReportDocument myReport = new ReportDocument();
myReport.Load(@"C:\myreport.rpt");
//create the modified dataset with the rows selected
myReport.SetDatasource(myDataSet);