How I can search rows in a datatable with a searchstring?

后端 未结 5 1118
清酒与你
清酒与你 2020-12-30 02:35

I want to search rows in my DataTable.

I\'ve tried this:

 protected void imggastsuche_Click(object sender, EventArgs e) 
        {
              


        
5条回答
  •  鱼传尺愫
    2020-12-30 03:06

    you could build the query you are going to use in the select.

                if(TextBoxCusName.Text != "")
                {
                    query = "CustomerName LIKE '%" + TextBoxCusName.Text.Trim()+"%' AND ";
                }
                if(TextBoxCusContact.Text != "")
                {
                    query = query + "CustomerNo LIKE '%" + TextBoxCusContact.Text.Trim() + "%' AND ";
                }
                if(TextBoxVehicleNo.Text != "")
                {
                    query = query + "VehicleNo LIKE '%" + TextBoxVehicleNo.Text.Trim()+"%'";
                }
                if(query.EndsWith("AND "))
                {
                    query = query.Remove(query.Length - 4);
                }
                DataRow[] result = dataCustomerAndVehicle.Select(query);
    

    this equivalent to

    select * from dataCustomerAndVehicle where CustomerName LIKE '%...%' AND ...
    

提交回复
热议问题