I am trying to read a SQL CE 4.0 database and I am getting the error HasRows = 'dr.HasRows' threw an exception of type 'System.InvalidOperationException'in both cases, however when I get all rows w/o any parameters I manage to get the necessary data. However, using parameters I cannot manage. A google search pointed me towards using
SqlCeDataReader dr = command.ExecuteResultSet(ResultSetOptions.Scrollable);
but this shows hasRows as false. I am sure that data exists otherwise a "SELECT *" would not work!
I am demoing some of my code maybe it helps;
SqlCeConnection con = new SqlCeConnection(Global.ConnectionString); SqlCeCommand cmd = new SqlCeCommand(query, con); cmd.CommandType = CommandType.Text; if (p.parent != "") { cmd.Parameters.Add(new SqlCeParameter("@PATIENT_PARENT", p.parent)); } try { con.Open(); SqlCeDataReader dr; dr = cmd.ExecuteReader(); while (dr.Read()) { } } catch (Exception ex) { throw new Exception(ex.Message); } finally { con.Close(); con.Dispose(); }Enlighten me please :)