-1

我有一个表单,我需要在组合框中以查询作为参数来提取项目列表。在数据库中,我有三个字段,如开发、网络金融等职位,它们根据复选框上的勾号存储为是或否。因此,如果一家公司有开发职位并且其被勾选,则以 dB 为单位的值为是,否则否。依此类推我试图在组合框中加载详细信息的表格,其中包含有可用职位的公司名称。并且我正在尝试从具有 dev,net,f​​in 作为项目的位置组合框中执行此操作,因此如果选择 dev 则查询应查找具有 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
4

1 回答 1

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;
于 2013-02-24T10:07:32.660 回答