2012-12-07 43 views
-1
select Preacher_Id , Name from Preacher_SkillDetail 
where Preacher_Id not in (
     where Preacher_FK from Event_Preacher 
     where (@newstartdate <= Start_Date and @newenddate >= Start_Date) 
     or (@newstartdate <= End_Date and @newenddate >= End_Date) 
     or (@newstartdate >= End_Date and @newenddate <= End_Date) 
     or (@newstartdate <= Start_Date and @newenddate >= End_Date) 
) 

我想bind the outputropdowncontrol我如何解決以下SQL查詢?

我怎麼能做到這一點在C#.NET?我有變數newstartdate and newenddate as Date

+0

@ hims056謝謝....但它仍然不工作 – Luv

+0

@ hims056它是一個子查詢。 – Kaf

+0

您的問題包含多個部分。從數據庫收集數據(SqlDataReader),將數據放入數據傳輸對象,然後在下拉菜單中顯示。伊姆舒爾這些單獨的步驟可以在SO或網上獲得。 –

回答

1
DataTable GetData() { 

    SqlConnection connection=new SqlConnection(); 
    connection.ConnectionString="Put your connection string"; 


    SqlCommand command = connection.CreateCommand(); 

    command.CommandText = "Your Sql Query Geos here"; 

    DataTable dt = new DataTable(); 

    try 
    { 
     command.Connection.Open(); 
     dt.Load(command.ExecuteReader()); 



    } 
    catch (Exception ex) 
    { 

     // Log ur error; 


    } 
    finally { 

     connection.Close(); 
    } 
    return dt; 
    } 

然後

Dropdownlist.Datasource=GetData(); 
Dropdownlist.DataBind(); 

指定的控件屬性您TextFiled和ValueField。

我認爲這應該工作。

0

您必須綁定下拉列表的DataTextField和DataValueField。 DataTextField是顯示下拉列表中的元素的字段。 DataValueField保存這些字段的ID。 如果您的查詢返回類似 Peacher_id |名稱 1 | Peacher 1 2 | Peacher 2 3 | Peacher 3 理想情況下,Peacher_Id應該綁定到DataValueField,Name應該綁定到DataTextField。你可以去下拉列表屬性並設置這些屬性。之後,您只需將數據源綁定到下拉列表。

dropdownlist.DataSource = ds; dropdownlist.DataBind();