<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL Server Compact Edition with C# and VB.Net</title>
	<atom:link href="http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/</link>
	<description>Making Microsoft .Net Development Magical</description>
	<lastBuildDate>Tue, 07 Feb 2012 16:57:33 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Javith</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-29693</link>
		<dc:creator><![CDATA[Javith]]></dc:creator>
		<pubDate>Mon, 01 Aug 2011 06:30:50 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-29693</guid>
		<description><![CDATA[Where does the database would hae been stored??]]></description>
		<content:encoded><![CDATA[<p>Where does the database would hae been stored??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jim Heath</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-29605</link>
		<dc:creator><![CDATA[Jim Heath]]></dc:creator>
		<pubDate>Sun, 10 Jul 2011 14:45:06 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-29605</guid>
		<description><![CDATA[This is very useful!  I am building an app for my archery club to track events and archers scores and awards.  We have been using Excel so I need to blast a bunch of data into my SSCE DB.  This is the ticket!  Thanks!]]></description>
		<content:encoded><![CDATA[<p>This is very useful!  I am building an app for my archery club to track events and archers scores and awards.  We have been using Excel so I need to blast a bunch of data into my SSCE DB.  This is the ticket!  Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nauman Shah</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-29246</link>
		<dc:creator><![CDATA[Nauman Shah]]></dc:creator>
		<pubDate>Tue, 12 Apr 2011 06:03:27 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-29246</guid>
		<description><![CDATA[I know that SQL Server CE supports Arabic but for that the device must support that locale. If the device does not have Arabic font installed and it does not support Arabic (Windows Mobile CE 4.20) what can be the alternative to handle this. I ll really appreciate if you or any one else can help. Thanks]]></description>
		<content:encoded><![CDATA[<p>I know that SQL Server CE supports Arabic but for that the device must support that locale. If the device does not have Arabic font installed and it does not support Arabic (Windows Mobile CE 4.20) what can be the alternative to handle this. I ll really appreciate if you or any one else can help. Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: seekaye2</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-29123</link>
		<dc:creator><![CDATA[seekaye2]]></dc:creator>
		<pubDate>Sun, 20 Mar 2011 10:39:00 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-29123</guid>
		<description><![CDATA[This code is very useful, many thanks

How can I sort the DGV by a column other than the primary key?

I tried

DGV.Sort(DGV.Columns(0), System.ComponentModel.ListSortDirection.Ascending)

but got the error &quot;DataGridView control cannot be sorted if it is bound to an IBindingList that does not support sorting.&quot;

thanks]]></description>
		<content:encoded><![CDATA[<p>This code is very useful, many thanks</p>
<p>How can I sort the DGV by a column other than the primary key?</p>
<p>I tried</p>
<p>DGV.Sort(DGV.Columns(0), System.ComponentModel.ListSortDirection.Ascending)</p>
<p>but got the error &#8220;DataGridView control cannot be sorted if it is bound to an IBindingList that does not support sorting.&#8221;</p>
<p>thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: aroratushar</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-28148</link>
		<dc:creator><![CDATA[aroratushar]]></dc:creator>
		<pubDate>Wed, 01 Dec 2010 20:20:09 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-28148</guid>
		<description><![CDATA[I have thoroughly used Sqlite in the past, it is complete, but lacks speed and has bugs, I discovered that Sqlite can&#039;t be used by even 3 Users doing long database operations at the same time. It just locks up. Now only yesterday, I finally realized and was shocked that Sql Server Compact Edition is a hidden magic tool, does all the things i dreamt of. Sql Server Compact Edition 3.5 is the best Embedded Database that you will ever find in the entire world. It is free! No bugs came ever with my handling of Sql CE.

Tushar]]></description>
		<content:encoded><![CDATA[<p>I have thoroughly used Sqlite in the past, it is complete, but lacks speed and has bugs, I discovered that Sqlite can&#8217;t be used by even 3 Users doing long database operations at the same time. It just locks up. Now only yesterday, I finally realized and was shocked that Sql Server Compact Edition is a hidden magic tool, does all the things i dreamt of. Sql Server Compact Edition 3.5 is the best Embedded Database that you will ever find in the entire world. It is free! No bugs came ever with my handling of Sql CE.</p>
<p>Tushar</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sofiene</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-28077</link>
		<dc:creator><![CDATA[sofiene]]></dc:creator>
		<pubDate>Sat, 13 Nov 2010 21:49:42 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-28077</guid>
		<description><![CDATA[thanks, your code is very useful, congratulations

but can i use it on pocket pc?]]></description>
		<content:encoded><![CDATA[<p>thanks, your code is very useful, congratulations</p>
<p>but can i use it on pocket pc?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sofiene</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-28076</link>
		<dc:creator><![CDATA[sofiene]]></dc:creator>
		<pubDate>Sat, 13 Nov 2010 21:48:43 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-28076</guid>
		<description><![CDATA[thnks, your code is very useful, congratulations

but can i use it on pocket pc?]]></description>
		<content:encoded><![CDATA[<p>thnks, your code is very useful, congratulations</p>
<p>but can i use it on pocket pc?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jSQL</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-27968</link>
		<dc:creator><![CDATA[jSQL]]></dc:creator>
		<pubDate>Sat, 04 Sep 2010 19:51:57 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-27968</guid>
		<description><![CDATA[Thank you! You saved me a whole lot of time!!!

for the sql += “WHERE (LastName LIKE ‘” + txtName.Text + “%’)”; issue try this:

sql += &quot;WHERE(LastName LIKE N&#039;&quot; + txtName.Text + &quot;%&#039;)&quot;;]]></description>
		<content:encoded><![CDATA[<p>Thank you! You saved me a whole lot of time!!!</p>
<p>for the sql += “WHERE (LastName LIKE ‘” + txtName.Text + “%’)”; issue try this:</p>
<p>sql += &#8220;WHERE(LastName LIKE N&#8217;&#8221; + txtName.Text + &#8220;%&#8217;)&#8221;;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dezso</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-27949</link>
		<dc:creator><![CDATA[Dezso]]></dc:creator>
		<pubDate>Mon, 23 Aug 2010 16:43:32 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-27949</guid>
		<description><![CDATA[This segment looks fine acording to the SQL Compact reference.
&quot;string sql = &quot;SLECT LastName, FirstName FROM CoolPeople &quot;;
            if (txtName.Text.Length &gt; 0)
            {
                sql += &quot;WHERE (LastName LIKE &#039;&quot; + txtName.Text + &quot;%&#039;)&quot;;
                
            }&quot;
ref:
&quot;SELECT cvchar from talltypes0 
WHERE cvchar like &#039;ab&#039; escape 7&quot;

but I&#039;m getting a error 
[Token line number = 1, Token line number = 7, Token in error = LastName ]

Whats wrong here ?!]]></description>
		<content:encoded><![CDATA[<p>This segment looks fine acording to the SQL Compact reference.<br />
&#8220;string sql = &#8220;SLECT LastName, FirstName FROM CoolPeople &#8220;;<br />
            if (txtName.Text.Length &gt; 0)<br />
            {<br />
                sql += &#8220;WHERE (LastName LIKE &#8216;&#8221; + txtName.Text + &#8220;%&#8217;)&#8221;;</p>
<p>            }&#8221;<br />
ref:<br />
&#8220;SELECT cvchar from talltypes0<br />
WHERE cvchar like &#8216;ab&#8217; escape 7&#8243;</p>
<p>but I&#8217;m getting a error<br />
[Token line number = 1, Token line number = 7, Token in error = LastName ]</p>
<p>Whats wrong here ?!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Barry G. Sumpter</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-27830</link>
		<dc:creator><![CDATA[Barry G. Sumpter]]></dc:creator>
		<pubDate>Tue, 22 Jun 2010 23:40:30 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-27830</guid>
		<description><![CDATA[Thaks to all who contributed.
I wanted to add my findings 
for developing my first database app 
for my windows mobile 6.5 platform on my HTC HD2.

PC development additional installs 
over and above my previous installs 
from my initial post directly above:
SSCEBOL-ENU.msi
SSCEDeviceRuntime-ENU.msi
SSCERuntime-ENU.exe

HTC HD2 installs:
sqlce.ppc.wce5.armv4i.CAB
sqlce.repl.ppc.wce5.armv4i.CAB]]></description>
		<content:encoded><![CDATA[<p>Thaks to all who contributed.<br />
I wanted to add my findings<br />
for developing my first database app<br />
for my windows mobile 6.5 platform on my HTC HD2.</p>
<p>PC development additional installs<br />
over and above my previous installs<br />
from my initial post directly above:<br />
SSCEBOL-ENU.msi<br />
SSCEDeviceRuntime-ENU.msi<br />
SSCERuntime-ENU.exe</p>
<p>HTC HD2 installs:<br />
sqlce.ppc.wce5.armv4i.CAB<br />
sqlce.repl.ppc.wce5.armv4i.CAB</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Barry G. Sumpter</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-27829</link>
		<dc:creator><![CDATA[Barry G. Sumpter]]></dc:creator>
		<pubDate>Tue, 22 Jun 2010 23:24:45 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-27829</guid>
		<description><![CDATA[Visual Studio 2008 Pro SP1
.net Framework 3.5 SP1
Reference
    System.Data.SqlServerCe 3.5.1.0

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Data.SqlServerCe
Imports System.IO

&#039;http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/




&#039;http://msdn.microsoft.com/en-us/library/bb986876.aspx



&#039;http://msdn.microsoft.com/en-us/library/aa983341.aspx
&#039;http://msdn.microsoft.com/en-us/library/13kw2t64(VS.90).aspx

Public Class Form1

    &#039;====================== assumed controls on the form:
    &#039;buttons:
    &#039; CreateDataBaseBtn
    &#039; CreateTableBtn
    &#039; LoadGridBtn
    &#039; LoadTableBtn
    &#039; ReadRecordsBtn
    &#039;labels:
    &#039; ResultsLbl
    &#039;textboxes:
    &#039; NameTxt
    &#039;DataGridView:
    &#039; dgvCoolPeople

    &#039;====================================== Services

    Private Function ConnectionString() As String
        Dim fileName As String = &quot;ArcaneCode.sdf&quot;
        Dim password As String = &quot;arcanecode&quot;
        Dim connectionStr As String

        connectionStr = &quot;DataSource=\&quot; &amp; fileName &amp; &quot;; Password=&quot; &amp; password

        Return connectionStr

    End Function

    Private Sub LoadRow(ByVal firstName As String, ByVal lastName As String, ByVal url As String)
        Dim connectionStr As String = ConnectionString()
        Dim connection As New System.Data.SqlServerCe.SqlCeConnection(connectionStr)

        If connection.State = ConnectionState.Closed Then
            connection.Open()
        End If

        Dim cmd As System.Data.SqlServerCe.SqlCeCommand

        Dim sqlInsertRowStatement As String = &quot;insert into CoolPeople (LastName, FirstName, URL) values &quot;
        sqlInsertRowStatement = sqlInsertRowStatement &amp; &quot;(@lastname, @firstname, @url)&quot;

        Try

            cmd = New System.Data.SqlServerCe.SqlCeCommand(sqlInsertRowStatement, connection)
            cmd.Parameters.AddWithValue(&quot;@lastname&quot;, lastName)
            cmd.Parameters.AddWithValue(&quot;@firstname&quot;, firstName)
            cmd.Parameters.AddWithValue(&quot;@url&quot;, url)
            cmd.ExecuteNonQuery()

            ResultsLbl.Text = &quot;Row Added.&quot;

        Catch sqlexception As System.Data.SqlServerCe.SqlCeException
            MsgBox(sqlexception.Message, MessageBoxButtons.OK + MessageBoxIcon.Hand, &quot;Error&quot;)

        Catch ex As Exception
            MsgBox(ex.Message, MessageBoxButtons.OK + MessageBoxIcon.Hand, &quot;Error&quot;)

        Finally
            connection.Close()

        End Try

    End Sub

    &#039; ======================================== Events

   


    

    Private Sub btnCreateDatabase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateDatabase.Click
        Dim fileName As String = &quot;\ArcaneCode.sdf&quot;
        Dim connectionStr As String = ConnectionString()
        Dim engine As System.Data.SqlServerCe.SqlCeEngine

        If System.IO.File.Exists(fileName) Then
            System.IO.File.Delete(fileName)
        End If

        engine = New System.Data.SqlServerCe.SqlCeEngine(connectionStr)

        engine.CreateDatabase()

        ResultsLbl.Text = &quot;Database Created.&quot;
    End Sub

    Private Sub btnCreateTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateTable.Click
        &#039; Issue a SQL command to create a table
        &#039; Note: this only creates the table, it doesnt put any rows in it.
        Dim connectionStr As String = ConnectionString()

        Dim connection As New System.Data.SqlServerCe.SqlCeConnection(connectionStr)

        If connection.State = ConnectionState.Closed Then
            connection.Open()
        End If

        Dim cmd As System.Data.SqlServerCe.SqlCeCommand

        Dim sqlCreateTableStatement As String = &quot;create table CoolPeople (LastName nvarchar (40) not null, &quot;
        sqlCreateTableStatement = sqlCreateTableStatement &amp; &quot;FirstName nvarchar (40), URL nvarchar (256) )&quot;

        cmd = New System.Data.SqlServerCe.SqlCeCommand(sqlCreateTableStatement, connection)

        Try

            cmd.ExecuteNonQuery()

            ResultsLbl.Text = &quot;Table created.&quot;

        Catch sqlexception As System.Data.SqlServerCe.SqlCeException
            MsgBox(sqlexception.Message, MessageBoxButtons.OK + MessageBoxIcon.Hand, &quot;Error&quot;)

        Catch ex As Exception
            MsgBox(ex.Message, MessageBoxButtons.OK + MessageBoxIcon.Hand, &quot;Oh Crap.&quot;)

        Finally
            connection.Close()

        End Try
    End Sub

    Private Sub btnLoadGrid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadGrid.Click
        Dim connectionStr As String = ConnectionString()

        Dim connection As New System.Data.SqlServerCe.SqlCeConnection(connectionStr)

        If connection.State = ConnectionState.Closed Then
            connection.Open()
        End If

        Try
            &#039; Set the command to use the table, not a query
            Dim cmd As System.Data.SqlServerCe.SqlCeCommand
            cmd = New System.Data.SqlServerCe.SqlCeCommand(&quot;CoolPeople&quot;, connection)
            cmd.CommandType = CommandType.TableDirect

            &#039; Get the Table

            Dim resultSet As System.Data.SqlServerCe.SqlCeResultSet
            resultSet = cmd.ExecuteResultSet(System.Data.SqlServerCe.ResultSetOptions.Scrollable)

            &#039; Load the result set into the database
            dgvCoolPeople.DataSource = resultSet

        Catch sqlexception As System.Data.SqlServerCe.SqlCeException
            MsgBox(sqlexception.Message, MessageBoxButtons.OK + MessageBoxIcon.Hand, &quot;Error&quot;)

        Catch ex As Exception
            MsgBox(ex.Message, MessageBoxButtons.OK + MessageBoxIcon.Hand, &quot;Oh Crap.&quot;)

        End Try

        &#039; Note, do not close the connection, if you do the grid won’t be able to display.
        &#039; For production code you probably want to make your result set (rs) a class level variable
    End Sub

    Private Sub btnLoadTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadTable.Click
        Try

            LoadRow(&quot;Carl&quot;, &quot;Franklin&quot;, &quot;http:\\www.dnrtv.com&quot;)
            LoadRow(&quot;Richard&quot;, &quot;Campbell&quot;, &quot;http:\\www.dotnetrocks.com&quot;)
            LoadRow(&quot;Leo&quot;, &quot;Laporte&quot;, &quot;http:\\www.twit.tv&quot;)
            LoadRow(&quot;Steve&quot;, &quot;Gibson&quot;, &quot;http:\\www.grc.com&quot;)
            LoadRow(&quot;Arcane&quot;, &quot;Code&quot;, &quot;http:\\arcanecode.wordpress.com&quot;)

        Catch ex As Exception
            MsgBox(ex.Message, MessageBoxButtons.OK + MessageBoxIcon.Hand, &quot;Oh Crap.&quot;)

        End Try
    End Sub

    Private Sub btnReadRecords_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadRecords.Click
        Dim connectionStr As String = ConnectionString()

        Dim connection As New System.Data.SqlServerCe.SqlCeConnection(connectionStr)

        If connection.State = ConnectionState.Closed Then
            connection.Open()
        End If

        &#039; Build the sql query. If this was real life I’d use a parameter for the where bit
        &#039; to avoid SQL Injection attacks.
        Dim sqlQuery As String = &quot;select LastName, FirstName from CoolPeople &quot;

        If (NameTxt.Text.Length &gt; 0) Then
            sqlQuery = sqlQuery &amp; &quot;where LastName like ‘&quot; &amp; NameTxt.Text &amp; &quot;%’&quot;
        End If

        Try

            Dim cmd As New System.Data.SqlServerCe.SqlCeCommand(sqlQuery, connection)
            cmd.CommandType = CommandType.Text

            &#039; if you don’t set the result set to scrollable HasRows does not work
            Dim resultSet As System.Data.SqlServerCe.SqlCeResultSet
            resultSet = cmd.ExecuteResultSet(System.Data.SqlServerCe.ResultSetOptions.Scrollable)

            &#039; If you need to be able to update the result set, instead use:
            &#039; cmd.ExecuteResultSet(ResultSetOptions.Scrollable &#124; ResultSetOptions.Updatable);

            If resultSet.HasRows Then
                &#039; Use the get ordinal function so you don’t have to worry about remembering what
                &#039; order your SQL put the field names in.
                Dim ordLastName As Integer = resultSet.GetOrdinal(&quot;LastName&quot;)
                Dim ordFirstname As Integer = resultSet.GetOrdinal(&quot;FirstName&quot;)

                &#039; Hold the output
                Dim stringBuilder As New System.Text.StringBuilder

                &#039; Read the first record and get it’s data
                resultSet.ReadFirst()
                stringBuilder.AppendLine(resultSet.GetString(ordFirstname) &amp; &quot; &quot; &amp; resultSet.GetString(ordLastName))

                &#039; Now read thru the rest of the records. When there’s no more data, .Read returns false.
                While resultSet.Read()
                    stringBuilder.AppendLine(resultSet.GetString(ordFirstname) &amp; &quot; &quot; &amp; resultSet.GetString(ordLastName))
                End While

                &#039;Show the output in the label
                ResultsLbl.Text = stringBuilder.ToString()

            Else

                ResultsLbl.Text = &quot;No Rows Found.&quot;
            End If

        Catch sqlexception As System.Data.SqlServerCe.SqlCeException
            MsgBox(sqlexception.Message, MessageBoxButtons.OK + MessageBoxIcon.Hand, &quot;Error&quot;)

        Catch ex As Exception
            MsgBox(ex.Message, MessageBoxButtons.OK + MessageBoxIcon.Hand, &quot;Oh Crap.&quot;)

        Finally
            &#039;we Don’t need it anymore so we’ll be good and close it. in a ‘real life’ situation
            &#039; connection would likely be class level
            connection.Close()
        End Try
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class]]></description>
		<content:encoded><![CDATA[<p>Visual Studio 2008 Pro SP1<br />
.net Framework 3.5 SP1<br />
Reference<br />
    System.Data.SqlServerCe 3.5.1.0</p>
<p>Imports System<br />
Imports System.Collections.Generic<br />
Imports System.ComponentModel<br />
Imports System.Data<br />
Imports System.Drawing<br />
Imports System.Text<br />
Imports System.Windows.Forms<br />
Imports System.Data.SqlServerCe<br />
Imports System.IO</p>
<p>&#8216;http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/</p>
<p>&#8216;http://msdn.microsoft.com/en-us/library/bb986876.aspx</p>
<p>&#8216;http://msdn.microsoft.com/en-us/library/aa983341.aspx<br />
&#8216;http://msdn.microsoft.com/en-us/library/13kw2t64(VS.90).aspx</p>
<p>Public Class Form1</p>
<p>    &#8216;====================== assumed controls on the form:<br />
    &#8216;buttons:<br />
    &#8216; CreateDataBaseBtn<br />
    &#8216; CreateTableBtn<br />
    &#8216; LoadGridBtn<br />
    &#8216; LoadTableBtn<br />
    &#8216; ReadRecordsBtn<br />
    &#8216;labels:<br />
    &#8216; ResultsLbl<br />
    &#8216;textboxes:<br />
    &#8216; NameTxt<br />
    &#8216;DataGridView:<br />
    &#8216; dgvCoolPeople</p>
<p>    &#8216;====================================== Services</p>
<p>    Private Function ConnectionString() As String<br />
        Dim fileName As String = &#8220;ArcaneCode.sdf&#8221;<br />
        Dim password As String = &#8220;arcanecode&#8221;<br />
        Dim connectionStr As String</p>
<p>        connectionStr = &#8220;DataSource=\&#8221; &amp; fileName &amp; &#8220;; Password=&#8221; &amp; password</p>
<p>        Return connectionStr</p>
<p>    End Function</p>
<p>    Private Sub LoadRow(ByVal firstName As String, ByVal lastName As String, ByVal url As String)<br />
        Dim connectionStr As String = ConnectionString()<br />
        Dim connection As New System.Data.SqlServerCe.SqlCeConnection(connectionStr)</p>
<p>        If connection.State = ConnectionState.Closed Then<br />
            connection.Open()<br />
        End If</p>
<p>        Dim cmd As System.Data.SqlServerCe.SqlCeCommand</p>
<p>        Dim sqlInsertRowStatement As String = &#8220;insert into CoolPeople (LastName, FirstName, URL) values &#8221;<br />
        sqlInsertRowStatement = sqlInsertRowStatement &amp; &#8220;(@lastname, @firstname, @url)&#8221;</p>
<p>        Try</p>
<p>            cmd = New System.Data.SqlServerCe.SqlCeCommand(sqlInsertRowStatement, connection)<br />
            cmd.Parameters.AddWithValue(&#8220;@lastname&#8221;, lastName)<br />
            cmd.Parameters.AddWithValue(&#8220;@firstname&#8221;, firstName)<br />
            cmd.Parameters.AddWithValue(&#8220;@url&#8221;, url)<br />
            cmd.ExecuteNonQuery()</p>
<p>            ResultsLbl.Text = &#8220;Row Added.&#8221;</p>
<p>        Catch sqlexception As System.Data.SqlServerCe.SqlCeException<br />
            MsgBox(sqlexception.Message, MessageBoxButtons.OK + MessageBoxIcon.Hand, &#8220;Error&#8221;)</p>
<p>        Catch ex As Exception<br />
            MsgBox(ex.Message, MessageBoxButtons.OK + MessageBoxIcon.Hand, &#8220;Error&#8221;)</p>
<p>        Finally<br />
            connection.Close()</p>
<p>        End Try</p>
<p>    End Sub</p>
<p>    &#8216; ======================================== Events</p>
<p>    Private Sub btnCreateDatabase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateDatabase.Click<br />
        Dim fileName As String = &#8220;\ArcaneCode.sdf&#8221;<br />
        Dim connectionStr As String = ConnectionString()<br />
        Dim engine As System.Data.SqlServerCe.SqlCeEngine</p>
<p>        If System.IO.File.Exists(fileName) Then<br />
            System.IO.File.Delete(fileName)<br />
        End If</p>
<p>        engine = New System.Data.SqlServerCe.SqlCeEngine(connectionStr)</p>
<p>        engine.CreateDatabase()</p>
<p>        ResultsLbl.Text = &#8220;Database Created.&#8221;<br />
    End Sub</p>
<p>    Private Sub btnCreateTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateTable.Click<br />
        &#8216; Issue a SQL command to create a table<br />
        &#8216; Note: this only creates the table, it doesnt put any rows in it.<br />
        Dim connectionStr As String = ConnectionString()</p>
<p>        Dim connection As New System.Data.SqlServerCe.SqlCeConnection(connectionStr)</p>
<p>        If connection.State = ConnectionState.Closed Then<br />
            connection.Open()<br />
        End If</p>
<p>        Dim cmd As System.Data.SqlServerCe.SqlCeCommand</p>
<p>        Dim sqlCreateTableStatement As String = &#8220;create table CoolPeople (LastName nvarchar (40) not null, &#8221;<br />
        sqlCreateTableStatement = sqlCreateTableStatement &amp; &#8220;FirstName nvarchar (40), URL nvarchar (256) )&#8221;</p>
<p>        cmd = New System.Data.SqlServerCe.SqlCeCommand(sqlCreateTableStatement, connection)</p>
<p>        Try</p>
<p>            cmd.ExecuteNonQuery()</p>
<p>            ResultsLbl.Text = &#8220;Table created.&#8221;</p>
<p>        Catch sqlexception As System.Data.SqlServerCe.SqlCeException<br />
            MsgBox(sqlexception.Message, MessageBoxButtons.OK + MessageBoxIcon.Hand, &#8220;Error&#8221;)</p>
<p>        Catch ex As Exception<br />
            MsgBox(ex.Message, MessageBoxButtons.OK + MessageBoxIcon.Hand, &#8220;Oh Crap.&#8221;)</p>
<p>        Finally<br />
            connection.Close()</p>
<p>        End Try<br />
    End Sub</p>
<p>    Private Sub btnLoadGrid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadGrid.Click<br />
        Dim connectionStr As String = ConnectionString()</p>
<p>        Dim connection As New System.Data.SqlServerCe.SqlCeConnection(connectionStr)</p>
<p>        If connection.State = ConnectionState.Closed Then<br />
            connection.Open()<br />
        End If</p>
<p>        Try<br />
            &#8216; Set the command to use the table, not a query<br />
            Dim cmd As System.Data.SqlServerCe.SqlCeCommand<br />
            cmd = New System.Data.SqlServerCe.SqlCeCommand(&#8220;CoolPeople&#8221;, connection)<br />
            cmd.CommandType = CommandType.TableDirect</p>
<p>            &#8216; Get the Table</p>
<p>            Dim resultSet As System.Data.SqlServerCe.SqlCeResultSet<br />
            resultSet = cmd.ExecuteResultSet(System.Data.SqlServerCe.ResultSetOptions.Scrollable)</p>
<p>            &#8216; Load the result set into the database<br />
            dgvCoolPeople.DataSource = resultSet</p>
<p>        Catch sqlexception As System.Data.SqlServerCe.SqlCeException<br />
            MsgBox(sqlexception.Message, MessageBoxButtons.OK + MessageBoxIcon.Hand, &#8220;Error&#8221;)</p>
<p>        Catch ex As Exception<br />
            MsgBox(ex.Message, MessageBoxButtons.OK + MessageBoxIcon.Hand, &#8220;Oh Crap.&#8221;)</p>
<p>        End Try</p>
<p>        &#8216; Note, do not close the connection, if you do the grid won’t be able to display.<br />
        &#8216; For production code you probably want to make your result set (rs) a class level variable<br />
    End Sub</p>
<p>    Private Sub btnLoadTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadTable.Click<br />
        Try</p>
<p>            LoadRow(&#8220;Carl&#8221;, &#8220;Franklin&#8221;, &#8220;http:\\www.dnrtv.com&#8221;)<br />
            LoadRow(&#8220;Richard&#8221;, &#8220;Campbell&#8221;, &#8220;http:\\www.dotnetrocks.com&#8221;)<br />
            LoadRow(&#8220;Leo&#8221;, &#8220;Laporte&#8221;, &#8220;http:\\www.twit.tv&#8221;)<br />
            LoadRow(&#8220;Steve&#8221;, &#8220;Gibson&#8221;, &#8220;http:\\www.grc.com&#8221;)<br />
            LoadRow(&#8220;Arcane&#8221;, &#8220;Code&#8221;, &#8220;http:\\arcanecode.wordpress.com&#8221;)</p>
<p>        Catch ex As Exception<br />
            MsgBox(ex.Message, MessageBoxButtons.OK + MessageBoxIcon.Hand, &#8220;Oh Crap.&#8221;)</p>
<p>        End Try<br />
    End Sub</p>
<p>    Private Sub btnReadRecords_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadRecords.Click<br />
        Dim connectionStr As String = ConnectionString()</p>
<p>        Dim connection As New System.Data.SqlServerCe.SqlCeConnection(connectionStr)</p>
<p>        If connection.State = ConnectionState.Closed Then<br />
            connection.Open()<br />
        End If</p>
<p>        &#8216; Build the sql query. If this was real life I’d use a parameter for the where bit<br />
        &#8216; to avoid SQL Injection attacks.<br />
        Dim sqlQuery As String = &#8220;select LastName, FirstName from CoolPeople &#8221;</p>
<p>        If (NameTxt.Text.Length &gt; 0) Then<br />
            sqlQuery = sqlQuery &amp; &#8220;where LastName like ‘&#8221; &amp; NameTxt.Text &amp; &#8220;%’&#8221;<br />
        End If</p>
<p>        Try</p>
<p>            Dim cmd As New System.Data.SqlServerCe.SqlCeCommand(sqlQuery, connection)<br />
            cmd.CommandType = CommandType.Text</p>
<p>            &#8216; if you don’t set the result set to scrollable HasRows does not work<br />
            Dim resultSet As System.Data.SqlServerCe.SqlCeResultSet<br />
            resultSet = cmd.ExecuteResultSet(System.Data.SqlServerCe.ResultSetOptions.Scrollable)</p>
<p>            &#8216; If you need to be able to update the result set, instead use:<br />
            &#8216; cmd.ExecuteResultSet(ResultSetOptions.Scrollable | ResultSetOptions.Updatable);</p>
<p>            If resultSet.HasRows Then<br />
                &#8216; Use the get ordinal function so you don’t have to worry about remembering what<br />
                &#8216; order your SQL put the field names in.<br />
                Dim ordLastName As Integer = resultSet.GetOrdinal(&#8220;LastName&#8221;)<br />
                Dim ordFirstname As Integer = resultSet.GetOrdinal(&#8220;FirstName&#8221;)</p>
<p>                &#8216; Hold the output<br />
                Dim stringBuilder As New System.Text.StringBuilder</p>
<p>                &#8216; Read the first record and get it’s data<br />
                resultSet.ReadFirst()<br />
                stringBuilder.AppendLine(resultSet.GetString(ordFirstname) &amp; &#8221; &#8221; &amp; resultSet.GetString(ordLastName))</p>
<p>                &#8216; Now read thru the rest of the records. When there’s no more data, .Read returns false.<br />
                While resultSet.Read()<br />
                    stringBuilder.AppendLine(resultSet.GetString(ordFirstname) &amp; &#8221; &#8221; &amp; resultSet.GetString(ordLastName))<br />
                End While</p>
<p>                &#8216;Show the output in the label<br />
                ResultsLbl.Text = stringBuilder.ToString()</p>
<p>            Else</p>
<p>                ResultsLbl.Text = &#8220;No Rows Found.&#8221;<br />
            End If</p>
<p>        Catch sqlexception As System.Data.SqlServerCe.SqlCeException<br />
            MsgBox(sqlexception.Message, MessageBoxButtons.OK + MessageBoxIcon.Hand, &#8220;Error&#8221;)</p>
<p>        Catch ex As Exception<br />
            MsgBox(ex.Message, MessageBoxButtons.OK + MessageBoxIcon.Hand, &#8220;Oh Crap.&#8221;)</p>
<p>        Finally<br />
            &#8216;we Don’t need it anymore so we’ll be good and close it. in a ‘real life’ situation<br />
            &#8216; connection would likely be class level<br />
            connection.Close()<br />
        End Try<br />
    End Sub</p>
<p>    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load</p>
<p>    End Sub<br />
End Class</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Agustin</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-27642</link>
		<dc:creator><![CDATA[Agustin]]></dc:creator>
		<pubDate>Tue, 06 Apr 2010 21:58:12 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-27642</guid>
		<description><![CDATA[I am using:
            SqlCeConnection cn = new SqlCeConnection(strConnection);

            if (cn.State == ConnectionState.Closed)
            {
                cn.Open();
            }

            SqlCeCommand cmd;

            string sql = &quot;insert into &quot; + vTabla + 
                &quot;(Nombre) &quot; +
                &quot;values (@Nombre)&quot;;

            try
            {
                cmd = new SqlCeCommand(sql, cn);
                cmd.Parameters.AddWithValue(&quot;@Nombre&quot;, &quot;xxxxx&quot;);
                cmd.ExecuteNonQuery();
            }
            catch
            { }

The program data are inserted, but when you exit debug mode, the data is not in the database. 

Thanks.]]></description>
		<content:encoded><![CDATA[<p>I am using:<br />
            SqlCeConnection cn = new SqlCeConnection(strConnection);</p>
<p>            if (cn.State == ConnectionState.Closed)<br />
            {<br />
                cn.Open();<br />
            }</p>
<p>            SqlCeCommand cmd;</p>
<p>            string sql = &#8220;insert into &#8221; + vTabla +<br />
                &#8220;(Nombre) &#8221; +<br />
                &#8220;values (@Nombre)&#8221;;</p>
<p>            try<br />
            {<br />
                cmd = new SqlCeCommand(sql, cn);<br />
                cmd.Parameters.AddWithValue(&#8220;@Nombre&#8221;, &#8220;xxxxx&#8221;);<br />
                cmd.ExecuteNonQuery();<br />
            }<br />
            catch<br />
            { }</p>
<p>The program data are inserted, but when you exit debug mode, the data is not in the database. </p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Problemas con Windows Vista - Foro</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-27472</link>
		<dc:creator><![CDATA[Problemas con Windows Vista - Foro]]></dc:creator>
		<pubDate>Sat, 06 Feb 2010 18:58:21 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-27472</guid>
		<description><![CDATA[[...]  Microsoft .NET Compact Framework 3.5 Redistributable - MS Windows Vista Compatible Software  SQL Server Compact Edition with C# and VB.Net Arcane Code  ErikEJ blogs about SQL Compact, .NET and related stuff: Running SQL Compact from CD-ROM (read only [...]]]></description>
		<content:encoded><![CDATA[<p>[...]  Microsoft .NET Compact Framework 3.5 Redistributable &#8211; MS Windows Vista Compatible Software  SQL Server Compact Edition with C# and VB.Net Arcane Code  ErikEJ blogs about SQL Compact, .NET and related stuff: Running SQL Compact from CD-ROM (read only [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Haroon</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-27453</link>
		<dc:creator><![CDATA[Haroon]]></dc:creator>
		<pubDate>Wed, 27 Jan 2010 22:34:18 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-27453</guid>
		<description><![CDATA[Hi,

fantastic example. It gave me the kick for building a solution.

Having the same error as Matthew two posts above on random installs (XP SP2 and SP3) never had this error on Vista or W7, yet.

The error appears when opening a database.]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>fantastic example. It gave me the kick for building a solution.</p>
<p>Having the same error as Matthew two posts above on random installs (XP SP2 and SP3) never had this error on Vista or W7, yet.</p>
<p>The error appears when opening a database.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matthew</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-26875</link>
		<dc:creator><![CDATA[Matthew]]></dc:creator>
		<pubDate>Thu, 16 Jul 2009 13:28:51 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-26875</guid>
		<description><![CDATA[We abandoned SQLce and started using SQLite. I doubt we&#039;ll even use SQLce again. It&#039;s got everything the MS product hasn&#039;t, including any silly restrictions where you can use it.
It&#039;s also faster and smaller. The learning curve to begin using it is short too. Never say I don&#039;t give you anything.]]></description>
		<content:encoded><![CDATA[<p>We abandoned SQLce and started using SQLite. I doubt we&#8217;ll even use SQLce again. It&#8217;s got everything the MS product hasn&#8217;t, including any silly restrictions where you can use it.<br />
It&#8217;s also faster and smaller. The learning curve to begin using it is short too. Never say I don&#8217;t give you anything.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ugo</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-26872</link>
		<dc:creator><![CDATA[Ugo]]></dc:creator>
		<pubDate>Wed, 15 Jul 2009 17:53:01 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-26872</guid>
		<description><![CDATA[We have the same problem : executeNonQuery() returns 1 for affected rows but when we open the table nothing!
App : Vb.Net  2005 + SQLCE 3.5

any suggestion or provide help!

Thanks.]]></description>
		<content:encoded><![CDATA[<p>We have the same problem : executeNonQuery() returns 1 for affected rows but when we open the table nothing!<br />
App : Vb.Net  2005 + SQLCE 3.5</p>
<p>any suggestion or provide help!</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raguraman</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-26820</link>
		<dc:creator><![CDATA[Raguraman]]></dc:creator>
		<pubDate>Tue, 16 Jun 2009 13:51:28 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-26820</guid>
		<description><![CDATA[Insert statement is not working in SQLCE. Generates no error. executeNonQuery() returns 1 for affected rows too. but, I am not able to view the added records in the SDF file.


any suggestion or provide help!


Thanks.]]></description>
		<content:encoded><![CDATA[<p>Insert statement is not working in SQLCE. Generates no error. executeNonQuery() returns 1 for affected rows too. but, I am not able to view the added records in the SDF file.</p>
<p>any suggestion or provide help!</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matthew</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-26711</link>
		<dc:creator><![CDATA[Matthew]]></dc:creator>
		<pubDate>Mon, 18 May 2009 13:20:11 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-26711</guid>
		<description><![CDATA[Hi

I am trying to create an sdf file with c# webservices on a windows 2003 server box but get this error and can&#039;t find any other help.

Unspecified error [ sqlcese30.sys.dll ]
- this is the error when the program does &quot;engine.CreateDatabase();&quot;
My code runs fine on my workstation. I&#039;ve checked folder permissions, I&#039;ve copied sqlcese30.sys.dll into the bin folder, I&#039;ve installed the SQL Server 2005 Compact Edition Developers SDK on the server...

Can you help me solve this error, please?

Cheers

Matthew]]></description>
		<content:encoded><![CDATA[<p>Hi</p>
<p>I am trying to create an sdf file with c# webservices on a windows 2003 server box but get this error and can&#8217;t find any other help.</p>
<p>Unspecified error [ sqlcese30.sys.dll ]<br />
- this is the error when the program does &#8220;engine.CreateDatabase();&#8221;<br />
My code runs fine on my workstation. I&#8217;ve checked folder permissions, I&#8217;ve copied sqlcese30.sys.dll into the bin folder, I&#8217;ve installed the SQL Server 2005 Compact Edition Developers SDK on the server&#8230;</p>
<p>Can you help me solve this error, please?</p>
<p>Cheers</p>
<p>Matthew</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Speener</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-26695</link>
		<dc:creator><![CDATA[Mark Speener]]></dc:creator>
		<pubDate>Sat, 09 May 2009 03:44:23 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-26695</guid>
		<description><![CDATA[Thanks for the VB 2008 example. It just solved a huge problem for me.]]></description>
		<content:encoded><![CDATA[<p>Thanks for the VB 2008 example. It just solved a huge problem for me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-26610</link>
		<dc:creator><![CDATA[Alex]]></dc:creator>
		<pubDate>Mon, 06 Apr 2009 18:34:01 +0000</pubDate>
		<guid isPermaLink="false">http://arcanecode.wordpress.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/#comment-26610</guid>
		<description><![CDATA[Hi, good web blog, I ´m mexican and your code is very useful, congratulations ¡¡¡¡
greetingd from mexico]]></description>
		<content:encoded><![CDATA[<p>Hi, good web blog, I ´m mexican and your code is very useful, congratulations ¡¡¡¡<br />
greetingd from mexico</p>
]]></content:encoded>
	</item>
</channel>
</rss>

