3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by krii017
0

Write this query on button_click event it will return every occurrence of your entered string in database

String Command="select OrderNumber, Address, City ,Zipcode from Table_name where OrderNumber like '%"+ searchTextBox.text+"%'"

Edited by abelLazm: n/a

0

You want to do an sql query which would return all the order numbers, which contains the inserted number in textBox? The order is not counting at all?

I can see you typed into a textBox 10078, and the return was 2 results: 1007851103 and 11007859.
2nd order number has 11 on the beginning - this is not what you wrote into textBox. So does it mean you return every single order number that contains at least all those numbers combination? This is strange. And it is leading no where.

0

If I was wrong in my last statement, you cna do it like:

private void textBox1_TextChanged(object sender, EventArgs e)
        {
            DataTable table = new DataTable();

            //getting new results:
            using (SqlConnection sqlConn = new SqlConnection("connectionString"))
            {
                string query = @"SELECT OrderNumber, Address, City, ZipCode FROM Customer WHERE OrderNumber = @number";
                SqlCommand cmd = new SqlCommand(query,sqlConn);
                cmd.Parameters.Add("@number", SqlDbType.Int).Value = textBox1.Text;               
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(table);
            }
            //clearing and populating listView:
            listView1.Items.Clear();
            foreach (DataRow dr in table.Rows)
            {
                ListViewItem lvi = new ListViewItem(dr[0].ToString());
                lvi.SubItems.Add(dr[1]);
                lvi.SubItems.Add(dr[2]);
                lvi.SubItems.Add(dr[3]);
                listView1.Items.Add(lvi);
            }
        }
0
lvi.SubItems.Add(dr[1]);
                lvi.SubItems.Add(dr[2]);
                lvi.SubItems.Add(dr[3]);

got an error it says cannot convert to System.Windows.Forms.listViewItems.ListViewSubItems

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.