Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 我想要在c#net中使用数据库返回值的自动完成文本框代码_Asp.net_.net - Fatal编程技术网

Asp.net 我想要在c#net中使用数据库返回值的自动完成文本框代码

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();

私有void txtBoxSearch_text已更改(对象发送方,事件参数e) {

        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;

    }
我想要一个作为搜索选项的文本框,这里有一些问题

  • 在com上设置CommandText,但执行cmd

  • 在变量和CommandText上都设置了%

  • 您添加了一个参数,但CommandText中没有该参数


  • 问题是什么?为什么你没有得到你想要的?有错误消息吗?需要html/js的帮助吗?我不会得到任何结果,而是得到ExecuteReader:CommandText属性尚未初始化错误如果这回答了问题,那么你应该检查一下