自动完成文本框

时间:2017-01-16 06:22:05

标签: c# sql-server windows visual-studio

我的winform中有一个文本框。我想用来自客户表的手机号码自动填充它。我已经编写了代码,但它没有自动完成。

   string CS = "data source=.; database=BillingSoftware; user id=sa; Password=9495640";
        SqlConnection con = new SqlConnection(CS);
        con.Open();
        SqlCommand cmd = new SqlCommand("SELECT Phone FROM Customers", con);
        SqlDataReader rdr = cmd.ExecuteReader();
        AutoCompleteStringCollection CustomerPhone = new AutoCompleteStringCollection();
        while (rdr.Read())
        {
            CustomerPhone.Add(rdr.GetString(0));
        }
        txt_customerPOS.AutoCompleteCustomSource = CustomerPhone;
        con.Close();

1 个答案:

答案 0 :(得分:1)

检查rdr.Read()是否有数据?

或致电"电话"列名

或致电rdr ["电话"]。ToString()