2013-02-24 66 views
-1

我有一個窗體,我需要將組合框中的項目列表以查詢作爲參數。 在數據庫中,我有三個領域,像開發,網絡財務這樣的位置,基於checkbox上的勾號存儲爲yes或no。如果公司具有dev的位置並且其打勾,則以dB爲單位的值是否則no.so在一個表格上,我試圖在組合框中加載具有可用職位的公司的名稱。並且我正在試圖從一個組合框的位置,它具有dev,net,f​​in作爲項目,所以如果選擇dev,那麼查詢應該尋找具有開發位置的公司,閱讀器應該讀取並顯示它在組合框中。對此的任何幫助.....這裏是我的代碼....提前致謝。如何在組合框中使用組合框加載組合框中的列表

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click 
    If ComboBox3.Text = "Developer" Then 
     Dim dbprovider As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Taher\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\Database1.accdb;Persist Security Info=False;" 
     Me.con = New OleDb.OleDbConnection 
     Dim sqlquery As String = "SELECT cname FROM company WHERE dev='"yes"';" 
     Dim command As New OleDb.OleDbCommand(sqlquery, con) 
     Dim reader As OleDb.OleDbDataReader 
     con.ConnectionString = dbprovider 
     con.Open() 

     reader = command.ExecuteNonQuery() 
     reader.Read() 

     ComboBox3.SelectedItem.ToString() 

    End If 
End Sub 

回答

1
public static List<string> GetAllExpenseType() 
     { 
      List<string> listExpenseType= new List<string>(); 
      SqlCommand command= null; 
      try 
      { 
       command = new SqlCommand("select expname from Hm_ExpType", DbConnection.OpenConnection()); 

       SqlDataReader reader = command.ExecuteReader(); 

       while (reader.Read()) 
       { 
        listExpenseType.Add(reader[0].ToString()); 
       } 

       reader.Close(); 
       DbConnection.CloseConnection(command.Connection); 

       return listExpenseType; 

      } 
      catch (Exception exp) 
      { 
       throw exp; 
      } 

      finally { DbConnection.CloseConnection(command.Connection); } 

      return listExpenseType; 
     } 




List<string> listexpType = ExpenseBO.GetAllExpenseType(); 
comboExpType.DataSource = listexpType; 
+0

這應該工作....感謝 – CrashOverride 2013-02-24 12:31:55