2015-06-22 43 views
0

如何訪問從SQL查詢返回的第二個值?顯然,我將第一個值分配給我的下拉列表,但我以後如何在runaquery方法中獲得employeeid值?以下是我想什麼做的,但不能確定如何獲得比第二個呼叫到SQL Server等該值並再次運行查詢...在下拉列表中訪問SQL查詢結果

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

我會做這種方式:

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) 
}