gpt4 book ai didi

javascript - 使用不同的连接字符串进行级联下拉列表

转载 作者:行者123 更新时间:2023-12-03 06:56:37 24 4
gpt4 key购买 nike

我的项目中有两个dropdownlist。我的整个项目使用一个 connectionstring 但对于这两个下拉列表,我想使用不同的 connectionstring

我已经在我的 web.config 文件中定义了所有连接字符串。下面是代码:-

<td style="width: 15%" class="field">
<select id="cmbRecdDept" runat="server" style="width: 25%" onchange="FunEmpFillDept()">
<option value="0">--Select--</option>
</select>
</td>
<td style="width: 15%" class="field">
<select id="cmbRecdEmp" runat="server" style="width: 25%" onchange="FunSelEmpRecd()">
<option value="0">--Select--</option>
</select>
</td>

后面的代码是

ObjPriDT = ObjPriDal.ExecuteDataTable("select distinct master_mkey, Type_Desc from type_mst_a a join emp_mst b on a. master_mkey=b.department_mkey where  b.status in ('A','S','R') order by Type_Desc");
cmbRecdDept.DataSource = ObjPriDT;
cmbRecdDept.DataTextField = "Type_Desc";
cmbRecdDept.DataValueField = "master_mkey";
cmbRecdDept.DataBind();
cmbRecdDept.Items.Insert(0, new ListItem("---Select---", "0"));
第一个列表的

onchange 我绑定(bind)了第二个列表,其代码如下:-

function FunEmpFillDept() {
document.getElementById('cmbRecdEmp').innerHTML = "";
var ObjPriOption = document.createElement("Option");
ObjPriOption.text = "ALL";
ObjPriOption.value = "0";
//document.getElementById('txtEmpID').value="0";
document.getElementById('cmbRecdEmp').add(ObjPriOption);
StrPriFnName = "FunFillEmp(" + document.getElementById('cmbRecdDept').value + ")";
var ObjPriXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
ObjPriXMLHTTP.open("GET", "FrmInwardXMLHTTP.aspx?para=" + StrPriFnName, false);
ObjPriXMLHTTP.send("");
if (ObjPriXMLHTTP.responseText != "") {
StrPriRow = ObjPriXMLHTTP.responseText.split('|');
for (IntPriI = 0; IntPriI < StrPriRow.length - 1; IntPriI++) {
StrPriCol = StrPriRow[IntPriI].split('~');
var ObjPriOption = document.createElement("Option");
ObjPriOption.text = StrPriCol[1];
ObjPriOption.value = StrPriCol[0];
document.getElementById('cmbRecdEmp').add(ObjPriOption);
}
}
}

其函数FunFillEmp如下

public static string FunFillEmp(object[] args)
{
string StrPriReturn = "";
DataAccessLayer ObjPriDt = new DataAccessLayer();

DataTable dt = new DataTable();
dt = ObjPriDt.ExecuteDataTable("select mkey,Emp_Name,emp_card_no from emp_mst where department_mkey=" + args[0].ToString() + " and status in ('A','S','R') order by 2");
if (dt.Rows.Count > 0)
{
for (int IntpriI = 0; IntpriI < dt.Rows.Count; IntpriI++)
{
StrPriReturn += dt.Rows[IntpriI][0].ToString() + "~" + dt.Rows[IntpriI][1].ToString() + "~" + dt.Rows[IntpriI][2].ToString() + "|";
}
}
return StrPriReturn;
}

如何为这两个下拉列表使用不同的连接字符串

更新

我的数据访问层代码

public DataAccessLayer(string connectionstring, Providers provider)
{
strConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

switch (provider)
{
case Providers.SqlServer:
objFactory = SqlClientFactory.Instance;
break;
case Providers.OleDb:
objFactory = OleDbFactory.Instance;
break;
case Providers.Oracle:
objFactory = OracleClientFactory.Instance;
break;
case Providers.ODBC:
objFactory = OdbcFactory.Instance;
break;
case Providers.ConfigDefined:
string providername = ConfigurationManager.ConnectionStrings["ConnectionString"].ProviderName;
switch (providername)
{
case "System.Data.SqlClient":
objFactory = SqlClientFactory.Instance;
break;
case "System.Data.OleDb":
objFactory = OleDbFactory.Instance;
break;
case "System.Data.OracleClient":
objFactory = OracleClientFactory.Instance;
break;
case "System.Data.Odbc":
objFactory = OdbcFactory.Instance;
break;
}
break;
}
objConnection = objFactory.CreateConnection();
objCommand = objFactory.CreateCommand();
objConnection.ConnectionString = strConnectionString;
objCommand.Connection = objConnection;
}

最佳答案

看来您必须修改 DataAccessLayer 类,在构造函数中传递连接字符串/添加一个方法来选择连接字符串

--更新--修改DataAccessLayer

public DataAccessLayer(string connectionstring, Providers provider)
{

strConnectionString = ConfigurationManager.ConnectionStrings[connectionstring].ConnectionString;

然后将其实例化为(对于 SQL Server)

DataAccessLayer ObjPriDt = new DataAccessLayer(ConfigurationManager.ConnectionStrings["ConnectionString"],Providers.SqlServer);

对于其他连接指定它

例如,如果是 ConnectionString2

DataAccessLayer ObjPriDt = new DataAccessLayer(ConfigurationManager.ConnectionStrings["ConnectionString2"],Providers.SqlServer);

关于javascript - 使用不同的连接字符串进行级联下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37248398/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com