Click here to Skip to main content
15,895,779 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hiii everyone . i have two connection string with same name and different database.and i have a login page there is a one dropdownlist .i want to select first database when select first drop down value.if we select second value then select second database .please help how can i do this ?
Posted

1 solution

in web config.. :)

HTML
<connectionstrings>
   <add name="connection1" providername="System.Data.SqlClient" connectionstring="Data Source=ServerName;Initial Catalog=Database1;User ID=sa;Password=***" />

 <add name="connection2" providername="System.Data.SqlClient" connectionstring="Data Source=PC1-PC\PC1SQL;Initial Catalog=Database2;User ID=sa;Password=***" />
 </connectionstrings>



CS page.. 1) First Dropdown.(ID="ddl1")

C#
protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
       {
           SqlConnection cn=new SqlConnection(ConfigurationManager.ConnectionStrings["Connection1"].ConnectionString)
       }


CS page.. 2) Second Dropdown.(ID="ddl2")

C#
protected void ddl2_SelectedIndexChanged(object sender, EventArgs e)
      {
          SqlConnection cn=new SqlConnection(ConfigurationManager.ConnectionStrings["Connection2"].ConnectionString)
      }
 
Share this answer
 
Comments
manvendra patel 1-Aug-14 4:03am    
thanks lot its working
Nirav Prabtani 1-Aug-14 5:07am    
Welcome manvendra.. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900