This my code in class Fungsi
- public void autocompele1(TextBox autotext)
- {
- conn = Koneksi.Conn;
- conn.Open();
- cmd = new SqlCommand("SELECT Nama_Barang FROM Tb_Barang ORDER BY Nama_Barang", conn);
- try
- {
-
- Reader = cmd.ExecuteReader();
- if(Reader.HasRows)
- {
- while (Reader.Read())
- {
- autotext.AutoCompleteCustomSource.Add(Reader["Nama_Barang"].ToString());
- }
- }
- else
- {
- MessageBox.Show("Data Not Found");
- }
- }
- catch(Exception ex)
- {
- MessageBox.Show("erorr" + ex.Message);
- }
-
- finally
- {
- conn.Close();
- Reader.Close();
- }
-
- }
and i called in form like this
- private void Form_Transaksi_Load(object sender, EventArgs e)
- {
- Fungsi auto = new Fungsi();
- auto.autocompele1(txt_NamaBarang);
- }