how to connect SQL CE database on PocketPC

M

Microsoft

I have one SQL CE database (two tables : one has 100 records, another has
30,000+ records) on my PocketPC.
And I try a lot of ways to connect and query it.

What components I have to use?
What commands I have to use?
How can I query it?

Thank you so much for any help.

Regards,
(e-mail address removed)
 
J

Jon Skeet [C# MVP]

Microsoft said:
I have one SQL CE database (two tables : one has 100 records, another has
30,000+ records) on my PocketPC.
And I try a lot of ways to connect and query it.

What components I have to use?
What commands I have to use?
How can I query it?

Use SqlCeDataAdapter, SqlCeConnection, SqlCeCommand etc. The
documentation for each of them should provide you with enough
information to go from there, if you've got other ADO.NET experience -
if not, look through a "normal" (desktop) ADO.NET tutorial first.
 
M

Microsoft

Yes, I try it, but fail.

My code is like this :
Dim SqlConnection1 As New System.Data.SqlClient.SqlConnection

Dim SqlSelectCommand1 As New System.Data.SqlClient.SqlCommand

Dim SqlDataAdapter1 As New System.Data.SqlClient.SqlDataAdapter

Dim SqlDataSet1 As New System.Data.DataSet

SqlConnection1.ConnectionString = "data source=" &
openFileDialog1.FileName() & ";Password=abc;persist security
info=True;packet size=4096"

SqlDataAdapter1.SelectCommand = SqlSelectCommand1

SqlSelectCommand1.CommandText = "SELECT * from tblBook"

SqlSelectCommand1.Connection = SqlConnection1

SqlConnection1.Open()

SqlDataAdapter1.Fill(SqlDataSet1)

SqlDataAdapter1.TableMappings.Add("tblBook", "strBookFullThai")

SqlDataSet1.Tables("tblBook").Columns("strBookFullThai")
 
J

Jon Skeet [C# MVP]

Microsoft said:
Yes, I try it, but fail.

My code is like this :

Right, and what goes wrong? Bear in mind that when you fill a DataSet,
it will only create tables called Table, Table1, Table2 etc as far as I
know.
 
F

Franky

If you whant to use CsqlCE you need to use SQLCE objects like this:
if(System.IO.File.Exists(@"\My Documents\TestDB.sdf"))
{
SqlCeConnection oConn = new SqlCeConnection(@"Data Source=\My
Documents\TestDB.sdf");
SqlCeCommand sqlProd;

sqlProd = new SqlCeCommand("SELECT * from tblBook", oConn);

SqlCeDataAdapter daProduct = new SqlCeDataAdapter(sqlProd);
if (daProduct == null)
{
dtsProduct = new DataSet();
}
dtsProduct.Clear();
daProduct.Fill(dtsProduct,"tblBook");
DataGrid1.DataSource = dtsProduct.Tables["tblBook"];
}


____________________
Franky
(e-mail address removed)



Microsoft said:
Yes, I try it, but fail.

My code is like this :
Dim SqlConnection1 As New System.Data.SqlClient.SqlConnection

Dim SqlSelectCommand1 As New System.Data.SqlClient.SqlCommand

Dim SqlDataAdapter1 As New System.Data.SqlClient.SqlDataAdapter

Dim SqlDataSet1 As New System.Data.DataSet

SqlConnection1.ConnectionString = "data source=" &
openFileDialog1.FileName() & ";Password=abc;persist security
info=True;packet size=4096"

SqlDataAdapter1.SelectCommand = SqlSelectCommand1

SqlSelectCommand1.CommandText = "SELECT * from tblBook"

SqlSelectCommand1.Connection = SqlConnection1

SqlConnection1.Open()

SqlDataAdapter1.Fill(SqlDataSet1)

SqlDataAdapter1.TableMappings.Add("tblBook", "strBookFullThai")

SqlDataSet1.Tables("tblBook").Columns("strBookFullThai")
 
V

Valentin Iliescu

You must use the classes from the System.Data.SqlServerCe
namespace (SqlCeEngine, SqlCeConnection, SqlCeDataAdapter,
SqlCeCommand etc.) not from the System.Data.SqlClient
namespace.
 
J

Jon Skeet [C# MVP]

Franky said:
If you whant to use CsqlCE you need to use SQLCE objects like this:

<snip>

Whoops - yes, having already pointed the OP to the SqlCe* classes, I
didn't notice that he then hadn't used them...
 
V

Valentin Iliescu

For example, to create a new SQL CE database, you use this
code (the new database will be created in the "Test.sdf"
file):

Dim connStr As String = "Data Source = Test.sdf; Password
= <password>"

Dim engine As New SqlCeEngine(connStr)
engine.CreateDatabase()
engine.Dispose()

To connect to this database use:

Dim conn As SqlCeConnection
conn = New SqlCeConnection(connStr)
conn.Open()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top