Home All Groups Group Topic Archive Search About

Working with database in C# Pocket PC

Author
6 Apr 2007 11:00 AM
Sheikko
Working with database in C# Pocket PC

Hi all,
I want to develop an application that work with DB on pocket PC.
I have added the DB to the project from Menu->Data->Add New Data
Source.
I want to insert some Rows in a table of this Db.
I know that I can create a connection and insert values with sql
statements like that:

        public void SaveSettings(TSaveSettings Values)
        {

            DBConnection = new SqlCeConnection();
            DBConnection.ConnectionString = @"Data Source = ..\My
Documents\Db.sdf";

            //Create a SqlCeCommand on your connection
            SqlCeCommand InsertCommand = DBConnection.CreateCommand();

            //Set the CommandText for the command
            //The ?'s represent parameters that will be set later
            InsertCommand.CommandText = "Insert Into Settings(ComPort)
Values (?)";

            //Add parameters and assign them the values from the
TextBoxes on the form
            InsertCommand.Parameters.Add(new SqlCeParameter("ComPort",
SqlDbType.NText));

            InsertCommand.Parameters["ComPort"].Value =
Values.ComPort;

            //Open the connection, execute the query
            DBConnection.Open();
            InsertCommand.ExecuteNonQuery();

            //Close the connection
            if (DBConnection.State == ConnectionState.Open)
                DBConnection.Close();
        }

in this way it work, but why I have added the Db to the project? I
want from my application to make operation on my DB without creating
connection, open it and close it by code, but I want to use smoe
things like dataset, adding rows by rows.add().. and so on.

Can you help me with some examples or tutorials on line?
thank you very much

Author
6 Apr 2007 1:36 PM
LaFlour
On Apr 6, 3:00 pm, "Sheikko" <shei***@gmail.com> wrote:

> Working with database in C# Pocket PC
> in this way it work, but why I have added the Db to the project? I

What do you meant? Can you make it clear?
Author
8 Apr 2007 11:43 AM
Ginny Caughey [MVP]
I'm not sure exactly what you're asking, but tutorials are available here:
http://www.microsoft.com/sql/editions/compact/default.mspx

--
Ginny


Show quote
"Sheikko" <shei***@gmail.com> wrote in message
news:1175857251.222744.245190@l77g2000hsb.googlegroups.com...
> Working with database in C# Pocket PC
>
> Hi all,
> I want to develop an application that work with DB on pocket PC.
> I have added the DB to the project from Menu->Data->Add New Data
> Source.
> I want to insert some Rows in a table of this Db.
> I know that I can create a connection and insert values with sql
> statements like that:
>
>        public void SaveSettings(TSaveSettings Values)
>        {
>
>            DBConnection = new SqlCeConnection();
>            DBConnection.ConnectionString = @"Data Source = ..\My
> Documents\Db.sdf";
>
>            //Create a SqlCeCommand on your connection
>            SqlCeCommand InsertCommand = DBConnection.CreateCommand();
>
>            //Set the CommandText for the command
>            //The ?'s represent parameters that will be set later
>            InsertCommand.CommandText = "Insert Into Settings(ComPort)
> Values (?)";
>
>            //Add parameters and assign them the values from the
> TextBoxes on the form
>            InsertCommand.Parameters.Add(new SqlCeParameter("ComPort",
> SqlDbType.NText));
>
>            InsertCommand.Parameters["ComPort"].Value =
> Values.ComPort;
>
>            //Open the connection, execute the query
>            DBConnection.Open();
>            InsertCommand.ExecuteNonQuery();
>
>            //Close the connection
>            if (DBConnection.State == ConnectionState.Open)
>                DBConnection.Close();
>        }
>
> in this way it work, but why I have added the Db to the project? I
> want from my application to make operation on my DB without creating
> connection, open it and close it by code, but I want to use smoe
> things like dataset, adding rows by rows.add().. and so on.
>
> Can you help me with some examples or tutorials on line?
> thank you very much
>

AddThis Social Bookmark Button