Am trying to load a crystal report in Crystal report viewer but with out giving a SetDataSource to ReportDocument Object RRS feed

  • Question

  • User1594408874 posted

    Hi All.

    Am trying to open a Crystal report in Crystal report viewer in VS2010. I had did the earlier in VS2008( I have Shared my code below).And this code worked fine in VS208. But am trying to do the same this in VS2010 but i couldn't . And when i googled i found codes which has SetDataSource for ReportDocument Object . But where as if you see my below code which i used in VS2008 does not has to SetDataSource.  I just have to pass the parameter and Load the report. and it worked fine.Please help me out to figure out the issue as my current project is running on VS2010 and i have been told not to use setdataSource.

    ConnectionInfo crConnectionInfo = new ConnectionInfo();
    ReportDocument cryRpt = new ReportDocument();
    string ConnectionString = "Data Source =; Database = ERP_THOMAS; User ID = ***; pwd = ***";

    string[] connections = ConnectionString.Split(';');
    crConnectionInfo.ServerName = connections[0].Substring(connections[0].LastIndexOf("=") + 1, connections[0].Length - (connections[0].LastIndexOf("=") + 1)).Trim();
    crConnectionInfo.DatabaseName = connections[1].Substring(connections[1].LastIndexOf("=") + 1, connections[1].Length - (connections[1].LastIndexOf("=") + 1)).Trim();
    crConnectionInfo.UserID = connections[2].Substring(connections[2].LastIndexOf("=") + 1, connections[2].Length - (connections[2].LastIndexOf("=") + 1)).Trim();
    crConnectionInfo.Password = connections[3].Substring(connections[3].LastIndexOf("=") + 1, connections[3].Length - (connections[3].LastIndexOf("=") + 1)).Trim();


    cryRpt.SetParameterValue("@id", QuotationID);

    for (int i = 0; i < cryRpt.DataSourceConnections.Count; i++)
    cryRpt.DataSourceConnections[i].SetConnection(crConnectionInfo.ServerName, crConnectionInfo.DatabaseName, crConnectionInfo.UserID, crConnectionInfo.Password);

    CrystalReportViewer1.ReportSource = cryRpt;

    Thursday, January 18, 2018 9:31 AM

All replies