我有一个表单,我需要在组合框中提取项目列表,并将查询作为参数。 在数据库中,我有三个字段用于开发,网络融资等位置,根据复选框上的勾选存储为是或否。如果公司有开发仓位,则勾选的值为dB,否则为no.so on一个表单我试图在组合框中加载有可用职位的公司的名称。并且我试图从一个组合框中为dev,net,fin作为项目的位置这样做,所以如果选择dev,那么查询应该查找具有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
答案 0 :(得分: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;