user960982
user960982

Reputation: 11

change connection string in crystal report at run time and take record according to new connection

I have change connection string at run time but it not picking the record from new connection string. Code is:

private void Report_Load(object sender, EventArgs e)
    {
        try
        {
            foreach (ConnectionInfo item in Tests1.DataSourceConnections)
            {
                item.SetConnection(@".\sqlexpress", @"C:\DBFile\fff2011.mdf", true);
            }
            crystalReportViewer1.ReportSource = Tests1;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

Upvotes: 1

Views: 621

Answers (1)

Bearington
Bearington

Reputation: 112

I have used ODBC as the datasource in the report to do this. That way you don't have to change the report or anything in code when going between live and test.

Upvotes: 1

Related Questions