Mfwamba Tshimanga

Mfwamba Tshimanga

  • NA
  • 155
  • 46.2k

Multiples filters: should be wront codes. Which solution?

Jan 23 2015 11:34 AM
Hi!

I would like to filter dates with two values once (dates + days + name).
But I receive this error message: "not sufficient parameters..."



    conn.Open();
            OleDbCommand cmd = conn.CreateCommand();
            cmd.CommandType = CommandType.Text;

            cmd.CommandText = "select * from personal where (date between ? and ?) and days = ? and (name = ?)";

            var param1 = new OleDbParameter("@StartDate", OleDbType.Date);
            var param2 = new OleDbParameter("@EndDate", OleDbType.Date);
            var param3 = new OleDbParameter("@name", OleDbType.VarChar); 
            var param4 = new OleDbParameter("@days", OleDbType.VarChar); 

            param1.Value = dataStart.Value.Date;
            param2.Value = dataFinal.Value.Date;
            param3.Value = days.Text;
            param4.Value = name.Text;

            if (dataStart.Value <= dataFinal.Value)
            {
                cmd.Parameters.Add(param1);
                cmd.Parameters.Add(param2);
            }
            else
            {
                cmd.Parameters.Add(param2);
                cmd.Parameters.Add(param1);
            }

            cmd.Parameters.Add(param3);

            cmd.ExecuteNonQuery();

            DataTable dt = new DataTable();
            OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            da.Fill(dt);

            conn.Close();
            dgvRpt2.DataSource = dt;
        }


Answers (5)