On Tue, 2 Sep 2003 08:20:10 -0700, "Mike" <mi*******@hotm ail.com>
wrote:
I am writing a .NET application in C# that uses Crystal
Reports. I want the crystal reports to grab information
from a database no matter where the database is
located. To do this, I want to create an ODBC connection
to the database at runtime in order for the report to
grab data from the database. Does anyone have a code
snippet that shows how to do this? Thank you very much
for your reply.
This site might be helpfull when creating the ConnectionStrin g.
How do you plan on telling your application where the DB is? It needs
to know that sooner or later... Will this be in the config-file?
using System.Configur ation; //for AppSettingsRead er
private string CreateConnStrin g(){
//in the connection string,make sure to use an easily traced value
//for the location of the data (e.g. VAL_TO_REPLACE)
const string CONN_STRING = "connectionstri ng goes here";
AppSettingsRead er rdr = new AppSettingsRead er ();
//take the key out of the app.config file ("appSetting s" element)
//<appSettings>
// <add key="location" value="myServer .myDomain.count rycode" />
//</appSettings>
string strLocation = (string)rdr.Get Value ("location",
Type.GetType (System.String) );
//return the connectionstrin g template with the location of the
//database inserted at the right spot
return CONN_STRING.Rep lace ("VAL_TO_REPLAC E", strLocation);
}
Now you can use that connectionstrin g with the targetted platform
(OleDb, ODBC, Sql, Oracle, ...)
Does OleDb work with Crystal Reports?
--
NULL