2017-01-16 109 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()