Last post Apr 18, 2012 07:41 AM by ericyzhou
Apr 16, 2012 07:39 AM|ericyzhou|LINK
Trying to make SqlDataSource control support multiple databases. And trying to avoid coding as much as possible
So I think having two SqlDataSource controls on the page is the best way, like below:
<asp:SqlDataSource id="mdb_sql" runat="server"
ConnectionString="<%$ ConnectionStrings: mydb_sql%>"
SelectCommand="SELECT FirstName, LastName, Title FROM Employees" />
<asp:SqlDataSource id="mydb_orcl" runat="server"
ConnectionString="<%$ ConnectionStrings: mydb_orcl%>"
SelectCommand="SELECT FirstName, LastName, Title FROM mydb.Employees" />
Then switch during page load:
void Page_Load(object sender, EventArgs e)
if (app_db == DataBaseType.Oracle)
gridViewEmployees.DataSourceID = "mydb_orcl";
I just wondering if there is any better way of doing this?
Apr 16, 2012 07:58 AM|nijhawan.saurabh|LINK
Well yes, an SqlDataSource can point to only one data source.
Apr 17, 2012 09:42 PM|Decker Dong - MSFT|LINK
Cosidering the technology of ASP.NET of the SqlDataSource， I think SqlDataSource（widely speaking，any data control can only allow a single type of DataBase to be connected with），So I'm afraid you have to do such things as what you've done。
Apr 18, 2012 07:41 AM|ericyzhou|LINK
Ok, I think this is the only way other than coding