Here is the code for that in VB.NET:
On the page load or button click or whatever you want to run the report on you need to add the following: configureCRYSTALREPORT()
Private Sub configureCRYSTALREPORT()
Dim myConnectionInfo As New ConnectionInfo()
myConnectionInfo.DatabaseName = "DatabserName"
myConnectionInfo.UserID = "UID"
myConnectionInfo.Password = "PWD"
setDBLOGONforREPORT(myConnectionInfo)
End Sub
Private Sub setDBLOGONforREPORT(ByVal myconnectioninfo As ConnectionInfo)
Dim mytableloginfos As New TableLogOnInfos()
mytableloginfos = CrystalReportViewer1.LogOnInfo
For Each myTableLogOnInfo As TableLogOnInfo In mytableloginfos
myTableLogOnInfo.ConnectionInfo = myconnectioninfo
Next
End Sub
-------------------------------------------------------------------------------------------------------------------------------------------------
Here is the code for that in C#:
private void setDBLOGONforREPORT(ConnectionInfo myconnectioninfo)
{
TableLogOnInfos mytableloginfos = new TableLogOnInfos();
mytableloginfos = CrystalReportViewer1.LogOnInfo;
foreach (TableLogOnInfo myTableLogOnInfo in mytableloginfos)
{
myTableLogOnInfo.ConnectionInfo = myconnectioninfo;
}
}
In Page Load....
ConnectionInfo myConnectionInfo = new ConnectionInfo();
myConnectionInfo.ServerName = "serverName";
myConnectionInfo.DatabaseName = "DatabaseName";
myConnectionInfo.UserID = "sa";
myConnectionInfo.Password = "pwd";
setDBLOGONforREPORT(myConnectionInfo);
No comments:
Post a Comment