On Tue, 2 Sep 2003 08:20:10 -0700, "Mike" <mi*******@hotmail.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 ConnectionString.
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.Configuration; //for AppSettingsReader
private string CreateConnString(){
//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 = "connectionstring goes here";
AppSettingsReader rdr = new AppSettingsReader ();
//take the key out of the app.config file ("appSettings" element)
//<appSettings>
// <add key="location" value="myServer.myDomain.countrycode" />
//</appSettings>
string strLocation = (string)rdr.GetValue ("location",
Type.GetType (System.String));
//return the connectionstring template with the location of the
//database inserted at the right spot
return CONN_STRING.Replace ("VAL_TO_REPLACE", strLocation);
}
Now you can use that connectionstring with the targetted platform
(OleDb, ODBC, Sql, Oracle, ...)
Does OleDb work with Crystal Reports?
--
NULL