2017-01-16 111 views
0

我在我的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

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

或称之为 “电话” 栏名

或拨打RDR [ “电话”]。的ToString()