Reputation: 5376
Can anyone provide a clear and simple example of how I can open a SSCE database and query it with a SELECT statement? Ultimately I'll need to do this on a system that I have no control over so whatever method/provider I use must be available by default on a standard Windows machine.
Thanks!
Upvotes: 0
Views: 839
Reputation: 5376
For anyone struggling with this, look at this article:
http://msdn.microsoft.com/en-us/library/aa983326.aspx
Then it's as simple as this:
Imports System.Data.SqlServerCe
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Try
Using conn As New SqlCeConnection
conn.ConnectionString = "Data Source=c:\Reporting.Database.sdf;Persist Security Info=False;"
conn.Open()
MsgBox("opened")
conn.Close()
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
Upvotes: 0
Reputation: 41759
Sample code here: http://erikej.blogspot.com/2010/07/getting-started-with-sql-server-compact.html and information on private deployment here: http://erikej.blogspot.com/2011/02/using-sql-server-compact-40-with.html
Upvotes: 1
Reputation: 4332
The following should work. you will have to add a reference to System.Data.SqlServerCe and create a using statement for it.
string connectionString = "my connection string";
string queryString = "select column from mytable where mycolumn = 'somevalue'";
using (var cnn = new SqlCeConnection(connectionString))
{
using (var cmd = new SqlCeCommand(queryString, cnn))
{
cnn.Open();
var da = new SqlCeDataAdapter(cmd);
var ds = new DataSet();
da.Fill(ds);
}
}
You can also use cmd.Parameters.Add
after you call cnn.Open();
to add parameters to your query.
Upvotes: 0