S
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
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