Reputation: 23
private void PrintPreview_Load(object sender, EventArgs e)
{
if (GlobalVariable.GlobGetRowID > 0)
{
try
{
BindingData();
}
catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }
}
}
private void BindingData()
{
try
{
using (SqlCeConnection con = new SqlCeConnection(GlobalVariable.ConnectionString))
{
con.Open();
string QueryBuild = "SELECT TravelOrderNo, RowDate, FirstName, MiddleName, LastName, PositionDesignation, OfficialStation, Destination, " +
"Purpose, DtOfDeparture, DtOfReturn, MeansOfTransportation, Fare, PerDiam, Others1, Others2, RemarksAndRecommendation, " +
"RecommendedBy, ApprovedBy, IntRow FROM TravelOrderTable Where IntRow = @param1";
using (SqlCeCommand cmd = new SqlCeCommand(QueryBuild, con))
{
cmd.Parameters.Add("@param1", SqlDbType.BigInt).Value = GlobalVariable.GlobGetRowID;
SqlCeDataReader read = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(read);
DataSet1 ds = new DataSet1();
ds.Tables[0].Merge(dt);
GlobalVariable.GetRptPath = System.Configuration.ConfigurationSettings.AppSettings["Reports"];
rpt.Load(Application.StartupPath + "\\TravelReport.rpt");
rpt.SetDataSource(ds);
crystalReportViewer1.ReportSource = rpt;
cmd.Dispose();
}
con.Close();
}
}
catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }
}
What I've Done:
I created a Crystal Report place it at "\bin\debug\Reports\TravelReport.rpt" I also click the option Choose a Crystal Reports in the Crystal Report Viewer option and Bind the Crystal Reports Path
On The Crystal Reports I Have Provide its Database Expert at My Connections Selected the Dataset1 which in my dataset1 i have created a TravelOrderTableAdapter
my Question is how can i make my codes right to make my crystal report viewer display the data i wanted to view based on my c# form paramater IntRow ID.
Please Help any who has experience this already im using local compact database just to let you know.
Upvotes: 2
Views: 975
Reputation: 11
This Is the code:-
crystalReportViewer1.ReportSource = @"C:\WorldSalesReport.rpt";
I am not a pro programmer but I also stoked with same problem in my software you need mention the location of "Report.rpt"
for this you can use
exestr = (Environment.GetCommandLineArgs()[0]);
which will give you the application (nm.exe) location "C:/nm.exe"
int exelen = exestr.Length;
exestr = exestr.Remove(exelen - 6, 6) + "Report.rpt";
In this I am removing the nm.exe from string .Then It will be "C:/" after I added the Report.rpt
Then you need only:-
crystalReportViewer1.ReportSource = exestr;
Upvotes: 1