ウェブサイトの接続文字列が管理されているかどうかは、ドロップダウンの選択によって異なります。 web.config
で接続文字を同時に選択
私が持っている:
<add name="DUM01"
connectionString="Data Source=CHETAN-PC\SQLEXPRESS;Initial Catalog=DUM01;Integrated Security=True"
providerName="System.Data.SqlClient"/>
<add name="DUM02"
connectionString="Data Source=CHETAN-PC\SQLEXPRESS;Initial Catalog=DUM02;Integrated Security=True"
providerName="System.Data.SqlClient"/>
クラスファイル:
public class ConnectionStr
{
public int iClientId = 0;
public string sCon = string.Empty;
public string StrConnection(string strClientName)
{
if (strClientName != string.Empty)
{
if (strClientName == "")
{
sCon = Convert.ToString(ConfigurationManager.ConnectionStrings[""]);
}
else if (strClientName == "DUM02")
{
sCon = Convert.ToString(ConfigurationManager.ConnectionStrings["DUM02"]);
}
else if (strClientName == "DUM01")
{
sCon = Convert.ToString(ConfigurationManager.ConnectionStrings["DUM01"]);
}
}
return sCon;
}
}
ドロップダウン:
<asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" CssClass="tr">
<asp:ListItem Text="--Select--" Value="0"></asp:ListItem>
<asp:ListItem Text="Simons Holidays" Value=""></asp:ListItem>
<asp:ListItem Text="RVL Logistics" Value="DUM02"></asp:ListItem>
<asp:ListItem Text="Simon Shipping" Value="DUM01"></asp:ListItem>
</asp:DropDownList>
ドロップダウンがSelectIndexChanged:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string sClientName = Convert.ToString(DropDownList1.SelectedItem.Value);
Session["ClientName"] = sClientName;
ConnectionStr objConnectionStr = new ConnectionStr();
string strConnection = objConnectionStr.StrConnection(sClientName);
if (Session["ClientName"] != null)
{
sClientName = Convert.ToString(Session["ClientName"]);
}
strConnection = objConnectionStr.StrConnection(sClientName);
SqlConnection scon1 = new SqlConnection(strConnection);
}
を
と私はそれを任意のWebフォームを使用する必要があるときに私が使用します。
public partial class Webforms_VendorsWithBoot : System.Web.UI.Page
{
public string sClientName = string.Empty;
public static string strConnection = string.Empty;
public static DataTable TableData = new DataTable();
public static string brcode = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["ClientName"] != null)
{
sClientName = Convert.ToString(Session["ClientName"]);
}
ConnectionStr objConnectionStr = new ConnectionStr();
strConnection = objConnectionStr.StrConnection(sClientName);
}
}
の両方でいくつかのテーブルため、データベースがDUM01が、私はDUM02が同時にも利用可能である必要が選択され、その逆されたときに今の状況がありますいくつかのwebformsでは、両方のデータベースにデータを挿入する必要があります。
これを解決するにはどうすればよいですか?ありがとうございます。
を作成することができます。クライアント名に基づいて、マスタデータベース内の同じクライアントで構成されたデータベースの接続を作成します。このアッチを使用して、web.configファイルのmasterデータベース接続文字列を設定する必要があります。 –
任意の例.... –
私の答えを確認してください –