private void textBox1_TextChanged(object sender, EventArgs e)
{
string SQl = "select soldto from region where soldto like '%"+textBox1 .Text .ToString ().Trim ()+"%'";
// string SQl = "select soldto from region where soldto like '" + textBox1.Text.ToString().Trim() + "%'";
DataTable dt = ReadTable(SQl);
if (dt.Rows.Count > 0)
{
this.listBox1.Visible = true;
this.listBox1.Items.Clear();
for (int i = 0; i < dt.Rows.Count; i++)
{
this.listBox1.Items.Add(dt.Rows [i][0].ToString ().Trim ());
}
}
}
public DataTable ReadTable(String strSql)
{
string strConn = " Data Source=IP;Initial Catalog=dbname;User ID=sa;Password=pwd";
DataTable dt = new DataTable();
SqlConnection Conn = new SqlConnection(strConn);
Conn.Open();
SqlDataAdapter Cmd = new SqlDataAdapter(strSql, Conn);
Cmd.Fill(dt);
Conn.Close();
return dt;
}
private void listBox1_SelectedValueChanged(object sender, EventArgs e)
{
if (this.listBox1.SelectedItems.Count > 0)
{
this.textBox1.Text = this.listBox1.SelectedItem.ToString();
}
}