Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I developed an application using Microsoft access as the database but now i want to switch to sql compact edition.
My code is as under
VB
Private Sub Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dr As SqlCeDataReader

        Try
            con.Open()
            sql = "select userid from login where utype = 'Admin'"
            cmd = New SqlCeCommand(Sql, con)
            dr = cmd.ExecuteReader

            If dr.HasRows = True Then
                While dr.Read
                    uid = dr.GetString(0)
                End While
            Else
                End
            End If            
            dr.Close()
            
        Catch ex As Exception
            MessageBox.Show("Db is CLosed " + ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error)           
        End Try
        fillUid()
    End Sub


Im getting an exception here as under

SQL Server Compact does not support calls to HasRows property if the underlying cursor is not scrollable.

Detail of Exception

System.InvalidOperationException was caught
Message="SQL Server Compact does not support calls to HasRows property if the underlying cursor is not scrollable."
Source="System.Data.SqlServerCe"
StackTrace:
at System.Data.SqlServerCe.SqlCeDataReader.get_HasRows() at WindowsApplication1.Login.Login_Load(Object sender, EventArgs e) in C:\Users\kashif\Documents\Visual Studio 2008\Projects\WindowsApplication1\WindowsApplication1\Login.vb:line 39
InnerException:



Please help me out of this problem
Posted

I Have Perfect Solution For SQLCE Datareader....Now You Can Use Like This.................

Dim cmd As SqlCeCommand
Dim dr As SqlCeDataReader
Dim i As Int32 = 0
cmd = New SqlCeCommand(str, con)

dr = cmd.ExecuteResultSet(ResultSetOptions.Scrollable)
If dr.HasRows = True Then
else
endif


************************************GC Kachhadia *************************
 
Share this answer
 
Comments
phil.o 3-Dec-13 8:06am    
Nice topic-digging!
You have to call .Read before you call .HasRows
 
Share this answer
 
Hi ,
Check this
There is no member called HasRows in .NET Compact Framework.
http://msdn.microsoft.com/en-us/library/system.data.sqlserverce.sqlcedatareader_members%28v=vs.71%29.aspx[^]
but for the rest of your code i believe it will work but there is some methods and member not supported in .NET Compact Framework.
Best Regards
M.Mitwalli
 
Share this answer
 
SqlCeDataReader dr = cmd.ExecuteResultSet(ResultSetOptions.Scrollable)
 
Share this answer
 
Comments
phil.o 3-Dec-13 8:06am    
Nice topic-digging!
Unless you're writing code for an embedded device, I wouldn't be using SQL Compact. Use SQL Express instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900