110,536
社区成员
发帖
与我相关
我的任务
分享
BindingSource bind = new BindingSource();
string str2 = "SELECT Top 10 Title, EmployeeID, ReportsTo, PostalCode FROM Employees";
private DataTable GetData(string strSQl)
{
DataTable dtData = new DataTable();
using (SqlConnection thisConnection = new SqlConnection(
@"Data Source=.;Initial Catalog=Northwind;Integrated Security=True"))
{
using (SqlDataAdapter thisAdapter = new SqlDataAdapter(
strSQl, thisConnection))
{
thisAdapter.Fill(dtData);
}
thisConnection.Close();
}
return dtData;
}
private void Form1_Load(object sender, EventArgs e)
{
bind.DataSource = GetData(str2);
this.comboBox1.DisplayMember = "Title";
this.comboBox1.DataSource = bind;
this.comboBox1.Text = string.Empty;
}
private void comboBox1_TextChanged(object sender, EventArgs e)
{
bind.Filter = string.Format("Title Like '{0}%'", this.comboBox1.Text);
this.comboBox1.DroppedDown = true;
}