在下拉列表中访问SQL查询结果

时间:2015-06-22 00:22:08

标签: c# asp.net sql-server-2008

如何访问SQL Query返回的第二个值?显然,我将返回的第一个值分配给我的下拉列表,但是我以后如何在runaquery方法中获取employeeid值?以下是我想做的,但不确定如何获得除第二次调用sql server之外的值并再次运行查询...

private void populate DropDownMainScreen()
{
  this.ddlemployee.DataSource = DoThis();
  this.ddlemployee.DataTextField = "employeename";
  this.ddlemployee.DataValueField = "employeename";
  this.ddlemployee.DataBind();
}

private void DoThis()
{
  SqlQueryBuilder = new StringBuilder();
  SqlQueryBuilder.Append = "Select employeeID, employeename from personell";
  //Actually run the query here
}
private void runaquery()
{
  string employeename = this.ddlemployee.SelectedItem.Value;
  int campaignID = ;
  Showmetheresults(RunSQLQuery, employeename, employeeID)
}

1 个答案:

答案 0 :(得分:1)

我会这样做:

private void populate DropDownMainScreen()
{
  this.ddlemployee.DataSource = DoThis();
  this.ddlemployee.DataTextField = "employeename";
  this.ddlemployee.DataValueField = "employeeID";
  this.ddlemployee.DataBind();
}

private void DoThis()
{
  SqlQueryBuilder = new StringBuilder();
  SqlQueryBuilder.Append = "Select employeeID, employeename from personell";
  //Actually run the query here
}
private void runaquery()
{
  string employeename = this.ddlemployee.SelectedItem.DataTextField;
  string employeID = this.ddlemployee.SelectedItem.Value;
  int campaignID = ;
  Showmetheresults(RunSQLQuery, employeename, employeeID)
}