如何在登录时在asp.net中从两个数据库中只选择一个数据库? [英] how to select only one database out of two database at login time in asp.net?
本文介绍了如何在登录时在asp.net中从两个数据库中只选择一个数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
在网络配置中.. :)
< connectionstrings >
< add < span class =code-attribute> name = connection1 providername = System.Data.SqlClient connectionstring = 数据源= ServerName;初始目录= Database1;用户ID = sa;密码= *** / >
< add name = connection2 providername = < span class =code-keyword> System.Data.SqlClient connectionstring = 数据源= PC1-PC\PC1SQL;初始目录= Database2;用户ID = sa;密码= *** / >
< < span class =code-leadattribute> / connectionstrings >
CS页面.. 1)第一次下拉。(ID =ddl1)
protected void ddl1_SelectedIndexChanged( object sender,EventArgs e)
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings [ Connection1]。ConnectionString)
}
CS页面.. 2)第二次下拉。(ID =ddl2)
protected void ddl2_SelectedIndexChanged( object sender,EventArgs e)
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings [ Connection2]。ConnectionString)
}
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 ?
解决方案
in web config.. :)
<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")
protected void ddl1_SelectedIndexChanged(object sender, EventArgs e) { SqlConnection cn=new SqlConnection(ConfigurationManager.ConnectionStrings["Connection1"].ConnectionString) }
CS page.. 2) Second Dropdown.(ID="ddl2")
protected void ddl2_SelectedIndexChanged(object sender, EventArgs e) { SqlConnection cn=new SqlConnection(ConfigurationManager.ConnectionStrings["Connection2"].ConnectionString) }
这篇关于如何在登录时在asp.net中从两个数据库中只选择一个数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文