Blissful MS Access with Crystal Report (No Database Path Problem!!!)

Many a times i wondered at the client end while delivering the software. Everything is fine but Crystal Report wanted the database path as the path varied between Client & Development PC. However in VB6 and Crystal Report 8+, 9 etc., saving the report without data solved this problem. In .net days, i was looking for a solid solution and finally reached to this point. Now I can use Crystal Report with .net at no database path selection at client location. However I think the following code block is worth mentioning for the guys facing similar problems like me.

[I didn’t use much Comments as you will surely understand the code if you already have come this far. :-)]
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data.OleDb;
//TopSheet is the Report Name in my case.
private TopSheet crDocument  = new TopSheet();
private Database crDB;
private Tables crTables;
private Table crTable;
private TableLogOnInfo crLogOnInfo;
private ConnectionInfo crConnectionInfo = new ConnectionInfo();

private void ShowReport(int Param){
string sqlString = @"<Your Select Statement>";
OleDbDataAdapter adoDataAdapter =
new OleDbDataAdapter(sqlString, <Your Database Connection>);
DataSet dS = new DataSet();
adoDataAdapter.Fill(dS, "Report");
crDocument  = new TopSheet();
crDocument .SetDataSource(dS.Tables[0]);
crDocument .SetParameterValue("prm1", Param);
crDB = crDocument .Database;
crTables = crDB.Tables;
crTable = crTables[0];
crLogOnInfo = crTable.LogOnInfo;
crLogOnInfo.ConnectionInfo =
//In my case I am using only a single table.
// If multiple tables then you
//can try looping through them.
//	foreach(crTable in crTables)
//	{
//        	crLogOnInfo = crTable.LogOnInfo;
//            	crLogOnInfo.ConnectionInfo = crConnectionInfo;
//            	crTable.ApplyLogOnInfo(crLogOnInfo);
//	} //End of Loop
 CrystalReportViewer1.ReportSource = crDocument ;dS.Dispose();

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s