Goran Bibic

Goran Bibic

  • 450
  • 2.9k
  • 180.4k

Filter datatable c#

May 26 2018 7:30 AM
Filter datatable from text box and datetime picker
 
  1. private void izvjestajoprodanimartiklima()  
  2.        {  
  3.            using (SqlConnection openCon = new SqlConnection(cs))  
  4.   
  5.            {  
  6.   
  7.                String saveStaff = "SELECT  roba as 'Naziv artikla', SUM (cast(kolicina as float)) as 'Kolicina' from (select roba, kolicina from mp_racun_roba union all select roba, kolicina from mp_faktura_roba) as alltables group by roba";  
  8.   
  9.   
  10.   
  11.   
  12.                if (!string.IsNullOrEmpty(textBox1.Text))  
  13.                {  
  14.                    saveStaff += "roba LIKE '%" + textBox1.Text + "%' ";  
  15.                }  
  16.   
  17.   
  18.                if (checkBox1.Checked)  
  19.                {  
  20.                    String strFilterDTP1 = dateTimePicker1.Value.ToString("yyyy-MM-dd");  
  21.                    String strFilterDTP2 = dateTimePicker2.Value.ToString("yyyy-MM-dd");  
  22.   
  23.     
  24.   
  25.                    saveStaff += strFilterDTP1 + " 00:00:00' AND '" + strFilterDTP2 + " 23:59:59' ";  
  26.                     
  27.                } 
 error   line 14   Incorrect syntax near the keyword 'LIKE'.
 
Some help?
 
 

Answers (4)