Re: create table by Ginny
Ginny
Tue Feb 27 15:15:36 CST 2007
Stefan,
Here's a short sample. You'd need to add error handling for production:
string sdfFile = "YourFile.sdf"; // this will be in root folder of device
since no path provided
SqlCeConnection conn;
if(File.Exists(sdfFile)
{
conn = new SqlCeConnection("Data Source="+sdfFile);
conn.Open();
}
else
{
// create database
SqlCeEngine engine = new SqlCeEngine("Data Source="+sdfFile);
engine.CreateDatabase();
conn = new SqlCeConnection("Data Source="+sdfFile);
conn.Open();
// create a table in the database
SqlCeCommand cmd = conn.CreateCommand();
cmd.CommandText = "Create table YourTable "+
"(SomeString nvarchar(50) not null, "+
" SomeOtherString nvarchar(50) not null, "+
" SomeInt int not null)";
cmd.ExecuteNonQuery();
}
// now your database is created, opened and has one table
conn.Close();
--
Ginny
"Stefan Dietl" <info@sdsoft.it> wrote in message
news:qmnwffu2uzsd$.1m587uh2aliop.dlg@40tude.net...
> Hi,
> has someone a short code example how to create an sdf.-database and table
> with the classes of the SqlServerCe-Namespace.
> Thanks
> Stefan