62,046
社区成员
发帖
与我相关
我的任务
分享
List<string> news = new List<string>();
public Form2()
{
InitializeComponent();
}
private void txtBind_TextChanged(object sender, EventArgs e)
{
string sqlSelect = "select name from kf_table where name like '%" + txtBind.Text + "%'";
SqlConnection conn = new SqlConnection(conStr);
SqlCommand cmd = new SqlCommand(sqlSelect, conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while(dr.Read())
{
news.Add(dr["name"].ToString());
}
conn.Close();
txtBind.AutoCompleteCustomSource.AddRange(news.ToArray());
}