Un poco de C#,JScript,VB, y CRM, Drupal, SQL , MSDCRM y MSDSL VBTools, developer, project lider, Social Media Activist, BlackBerry developer, telerik tools. (MCITP)
jueves, 24 de mayo de 2012
Crystal report connection
public CrystalDecisions.CrystalReports.Engine.ReportClass GetReport(string stringFromDate, string stringToDate, string stringOfficeID)
{
try {
// Create an instance of the report and set it's datasource.
string sType = "ReportsNameSpace.Report";
Type reportType = Type.GetType(sType, true, true);
if (reportType != null) {
// Create an instance of the report and set it's datasource.
CrystalDecisions.CrystalReports.Engine.ReportClass rpt = (CrystalDecisions.CrystalReports.Engine.ReportClass)Activator.CreateInstance(reportType);
ParameterFieldDefinitions crParameterFieldDefinitions = default(ParameterFieldDefinitions);
crParameterFieldDefinitions = rpt.DataDefinition.ParameterFields;
SCRCollectionEnumerator en = crParameterFieldDefinitions.GetEnumerator();
while ((en.MoveNext())) {
ParameterFieldDefinition param = default(ParameterFieldDefinition);
param = en.Current;
ParameterValues crValue = new ParameterValues();
// you have to check for parameter name
// and pass values
if ((param.Name == "@FromDate")) {
crValue.AddValue(stringFromDate);
param.ApplyCurrentValues(crValue);
} else if ((param.Name == "@ToDate")) {
crValue.AddValue(stringToDate);
param.ApplyCurrentValues(crValue);
}
}
TableLogOnInfo logOnInfo = new TableLogOnInfo();
// I am assuming that you have crystal server database
// connection strings in your web.config
logOnInfo.ConnectionInfo.ServerName = ConfigurationManager.AppSettings("CrystalServer").ToString();
logOnInfo.ConnectionInfo.UserID = ConfigurationManager.AppSettings("CrystalUser").ToString();
logOnInfo.ConnectionInfo.Password = ConfigurationManager.AppSettings("CrystalPassword").ToString();
TableLogOnInfo login = default(TableLogOnInfo);
foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in rpt.Database.Tables) {
login = tbl.LogOnInfo;
login.ConnectionInfo.ServerName = ConfigurationManager.AppSettings("CrystalServer").ToString();
login.ConnectionInfo.UserID = ConfigurationManager.AppSettings("CrystalUser").ToString();
login.ConnectionInfo.Password = ConfigurationManager.AppSettings("CrystalPassword").ToString();
tbl.ApplyLogOnInfo(login);
}
return rpt;
} else {
return null;
}
} catch (Exception ex) {
throw ex;
}
}
Fuente: http://forums.asp.net/p/1584368/4000328.aspx
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario