I’m trying to learn about C# with SQL CE so that my program can remember stuff.
I have created a database and can connect to it:
SqlCeConnection conn =
new SqlCeConnection(@"Data Source=|DataDirectory|\dbJournal.sdf");
conn.Open();
And it connects right, I guess cause if I rename the dbJournal.sdf to something wrong it doesn’t debug right.
Let’s say I want to make a simple SELECT query.
(SELECT * FROM tblJournal)
How is that done?
What about a simple insert?
(INSERT TO tblJournal (column1, column2, column2) VALUES
(value1, value2, value3))
I’m used to PHP and MySQL (as you properly can see :o))
@Chuck mentions EntityFramework which simplifies things and does all the work of writing the sql for you.
But there is a basic ADO.NET approach here which I will describe below.
The classes follow a standard pattern so to insert/read from sql server or other databases there are exact replica classes like
SqlConnectionorOleDbConnectionandOleDbCommandetcThis is the most barebones ado.net approach:
Then to read data :
A nice and quicker way to read data is like this:
This gets the entire data in one shot into a DataTable class.
To insert data :