Violeta Popa

Violeta Popa

  • NA
  • 137
  • 164k

filter listview

Mar 24 2013 6:10 PM
hi :)

i want to display in a listview only the insurances that have the expiration day between two dates, here's my code...please tell me what's wrong :(

            DateTime date1 = dateTimePicker1.Value;
            DateTime date2 = dateTimePicker2.Value;

            listView1.Items.Clear();
            SqlCommand cmd = new SqlCommand("SELECT * FROM client JOIN obtine ON client.id_client=obtine.id_client JOIN polita ON obtine.cod_polita=polita.cod_polita", conn);
            SqlDataReader dataReader = cmd.ExecuteReader();
            
            while (dataReader.Read())
            {
                string[] array = dataReader["perioada_asigurare"].ToString().Split('-');
                DateTime dt1 = DateTime.Parse(array[1]);

                //int result1=DateTime.Compare(date1,dt1);     i tried this too
                //int result2 = DateTime.Compare(date2, dt1);

                if (dt1>=date1 && dt1 <= date2)
                {
                    ListViewItem item = new ListViewItem(dataReader["denumire"].ToString());
                    item.SubItems.Add(dataReader["societate"].ToString());
                    item.SubItems.Add(dataReader["tip_polita"].ToString());
                    item.SubItems.Add(dataReader["serie"].ToString());
                    

                    listView1.Items.Add(item);
                }
            }

Answers (2)