Quantcast
Channel: SQL Server Compact Forum
Viewing all articles
Browse latest Browse all 193

Something strange in SQL CE 4.0

$
0
0

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 :)

Viewing all articles
Browse latest Browse all 193

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>