2013-02-24 39 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