以下是我用于搜索的代码,它在我们输入整个名称时会返回一个值,但我需要一个自动填充文本框,当我输入部分名称时会显示建议。
private void textBox3_KeyUp_1(object sender, System.Windows.Input.KeyEventArgs e)//Name Search
{
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select [Patient ID],[Patient Name],[Gender],[StudyDateTim],[Modality],[Study Name] From RepView Where [Patient Name] like '%" + textBox3.Text + "%'";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
dataGrid1.ItemsSource = dt.DefaultView;
con.Close();
}