我想将值传递给参数TYPE 1`。但我不知道该怎么做。请帮助
string constr = ConfigurationManager.ConnectionStrings["OracleConn"].ConnectionString;
string strQuery = "SELECT * FROM xxcus.xxacl_pn_expense_info";
int count = 1;
List<OracleParameter> parameters = new List<OracleParameter>();
List<string> conditions = new List<string>();
foreach (ListItem li in ddlStatus.Items)
{
if (li.Selected)
{
conditions.Add(string.Format(":TYPE{0}", count));
//OracleParameter p = new OracleParameter(string.Format(":TYPE{0}"), OracleType.VarChar);
OracleParameter p = new OracleParameter(string.Format(":TYPE{0}", count), OracleType.NVarChar);
p.Value = li.Value;
parameters.Add(p);
count++;
}
}
string whereCondition = string.Empty;
if (conditions.Count > 0)
{
whereCondition = " Where type IN (" + string.Join(",", conditions) + ")";
}
using (OracleConnection conn = new OracleConnection(constr))
{
using (OracleCommand cmd = new OracleCommand(strQuery + whereCondition))
{
cmd.Parameters.AddRange(parameters.ToArray());
cmd.Parameters.Add(":TYPE", OracleType.VarChar) = what to pass here?
using (OracleDataAdapter oda = new OracleDataAdapter(cmd))
{
cmd.Connection = conn;
using (DataTable dtcheck = new DataTable())
{
oda.Fill(dtcheck);
GridExpInfo.DataSource = dtcheck;
GridExpInfo.DataBind();
}
}
}
}
答案 0 :(得分:1)
你不应该循环,看看它是否被选中。可以通过以下几种方法检索该值:
var value = dropdown.SelectedValue;
var text = dropdown.SelectedItem.Text;
可以找到更多详细信息here。