Asp.net 我想要在c#net中使用数据库返回值的自动完成文本框代码
私有void txtBoxSearch_text已更改(对象发送方,事件参数e) {Asp.net 我想要在c#net中使用数据库返回值的自动完成文本框代码,asp.net,.net,Asp.net,.net,私有void txtBoxSearch_text已更改(对象发送方,事件参数e) { AutoCompleteStringCollection namecollection = new AutoCompleteStringCollection(); SqlConnection con = new SqlConnection("connectionn string"); SqlCommand cmd = new SqlCommand();
AutoCompleteStringCollection namecollection = new AutoCompleteStringCollection();
SqlConnection con = new SqlConnection("connectionn string");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
string searchFor = "%" + txtBoxSearch.Text + "%";
com.CommandText = "select cust_nm from Customer_Info where (cust_nm LIKE ' % " + searchFor + " %') ";
con.Open();
cmd.Parameters.AddWithValue("@name", searchFor);
SqlDataReader rea = cmd.ExecuteReader();
if (rea.HasRows == true)
{
while (rea.Read())
namecollection.Add(rea["name"].ToString());
}
rea.Close();
txtBoxSearch.AutoCompleteMode = AutoCompleteMode.Suggest;
txtBoxSearch.AutoCompleteSource = AutoCompleteSource.CustomSource;
txtBoxSearch.AutoCompleteCustomSource = namecollection;
}
我想要一个作为搜索选项的文本框,这里有一些问题
问题是什么?为什么你没有得到你想要的?有错误消息吗?需要html/js的帮助吗?我不会得到任何结果,而是得到ExecuteReader:CommandText属性尚未初始化错误如果这回答了问题,那么你应该检查一下