Marvin kakuru

Marvin kakuru

  • 1.1k
  • 355
  • 160.1k

simple contacts book

Mar 12 2011 2:35 PM

hi there, i am trying to populate a c sharp listbox with names from an sql database. but i can only view a name when i type the entire name. Is there a way i can view names as i type into the textbox according to the letters already typed.

this way i can be able to view a number of similar names and select the one i am interested in.

this is the code i am using

private void

{







{

conn.Open();

rdr = cmd.ExecuteReader();


listBox1.Items.Clear();

listBox2.Items.Clear();



{

listBox1.Items.Add(rdr[0]);

listBox2.Items.Add(rdr[1]);



}

}

}

}

}

textBox1_TextChanged(object sender, EventArgs e)SqlDataReader rdr = null;SqlConnection conn = new SqlConnection("Data Source=KATOTO-PC;Initial Catalog =contacts;User ID=sa;Password=Kyozi");SqlCommand cmd = new SqlCommand("SELECT name,contact FROM contacts where name = '" + textBox1.Text + "'", conn);while (rdr.Read())

Answers (5)