This is a migrated thread and some comments may be shown as answers.

Set Report Parameter Connection String

3 Answers 165 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 2
Dan asked on 09 Sep 2010, 01:55 PM
I have two report parameters which need to have their data populated via a SQL datasource.  I see how to do this by setting up a SQL dataadapter in the report and then setting the adapter as the DataSource for the report parameter.

The issue that I have is this.  I distribute this website to multiple clients.  Each client has a different SQL connection string which I store in the appSettings in web.config.  I cannot figure out how to set or associate this connection string at runtime from the appSetting to the report dataadapter connection.  Is there a way in the code behind to do this?

Thanks.
Dan

3 Answers, 1 is accepted

Sort by
0
Accepted
Patrick
Top achievements
Rank 1
answered on 09 Sep 2010, 04:00 PM
put the following after the call to the InitializeComponent() method in the report constructor, replacing "foobar" with a valid connection string of course :), and renaming the table adapter, data set and data table accordingly:

this.myDataSetTableAdapter1.Connection.ConnectionString = "foobar";
this.myDataSetTableAdapter1.Fill(this.myDataSet.MyDataSetTable);
0
Dan
Top achievements
Rank 2
answered on 09 Sep 2010, 04:36 PM
Excellent.  That fixed it.  Thanks so much.

Dan
0
Patrick
Top achievements
Rank 1
answered on 09 Sep 2010, 04:53 PM
I got that code from somewhere, can't remember where. Glad it helped!
Tags
General Discussions
Asked by
Dan
Top achievements
Rank 2
Answers by
Patrick
Top achievements
Rank 1
Dan
Top achievements
Rank 2
Share this question
or