-1

パラメータとしてクエリを使用してコンボボックスに項目リストをプルする必要があるフォームがあります。データベースには、開発、ネットワーク金融などのポジションの3つのフィールドがあり、チェックボックスのチェックに基づいてyesまたはnoとして保存されます。そのため、会社にdevのポジションがあり、チェックされている場合、dBの値はYesであり、それ以外の場合はno.soフォーム コンボ ボックスに詳細を読み込もうとしています。ポジションが利用可能な会社の名前です。そして、私はdev、net、finを項目として持つ位置のコンボボックスからそれをやろうとしているので、devを選択すると、クエリは開発位置がyesの会社を探し、リーダーはそれを読んで表示する必要がありますコンボボックスで。これに関するヘルプ.....ここに私のコードがあります....事前に感謝します。

 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 に答える