Ian Myers

Help

This is the Help file. It contains some basic information on how to use this program, and some advanced information on how it actually works.

Basics

Data can be both viewed, entered and edited in the same table.

Delete Press to delete data in a row or an entire row.

Enter Press to move to the next row. Changes are automatically saved without pressing anything.

Tab Press to move cursor from column to column and row to row.

Using your mouse: You can select an entire row on the table: Single Left-Click, or a single cell: Double Left-Click.

This program can be used by someone who just wants to be able to create their own custom lists, such as a list of favorite foods, wish list, etc... It can also be used for small businesses that don't want to pay a programmer to create a database program specifically for their needs. And lastly this program can be used by programmers who want to learn how to use SqlCE and WPF DataGrids.

Overview

This program allows you to save and retrieve information. It uses compact databases to accomplish this. Databases store multiple tables. A table can be thought of as a list of information, such as a list of contact that stores their names, e-mail and phone number. So in this sense a database is a kind of like a list of lists. When you open up a database you can grab specific types of lists (tables) and view their contents.

This program loads a default database when it starts up with some basic tables built in. You can choose to load a different database from the start menu, which are .SDF files, such as: Default.sdf

Once a database is select (the default one or one that you choose), a list of table names comes up on the left side. When you select a table from this list, its contents show in a table on the right side.

This table not only displays data but it allows you to change the data you see, as well as add more data. All changes you make are automatically saved to the table.

Technical

This program uses Microsoft SQL Server Compact Edition (SqlCE). The compact edition of SQL Server is easier to use. Databases are stored in a single .SDF file, instead of across multiple files. Each .SDF file can be up to 4GB. They can also be stored in your program. Regular SQL Server must be installed on the computer that your program runs on, and your program must connect to it. The compact edition allows your program to connect to a single .SDF file (ex: MyData.sdf) inside of its folder. You can open different .SDF file to connect to different data, and copy a .SDF file and just rename it to create whole new databases.

Viewing Databases

When you open a a data source, which is a compact database in this case (.SDF file), the first thing that happens is that the name of every single table inside of it is displayed in a list.

The contents of the data source (.SDF file) is dumped into an object called a DataSet. DataSets contain a DataTable object inside of them. You can add rows and columns to the DataTable.

The DataTable of the DataSet is then converted into a DataView object. A DataView is does not have rows and columns like the DataTable. A DataView is a list array. The objects it holds are equivalent to the rows in a DataTable, and the properties of the objects it holds are equivalent to the columns to a DataTable. You can sort data in the DataView.

The DataView is then used by a DataGrid control, which is the actual table you see in the program that displays all the data. Once the DataGrid.ItemsSource is assigned to a DataView, it automatically displays what's inside the DataView as rows and columns.

In short this is how data from a data source is sent to a DataGrid to be displayed:
Data source (.SDF file) ---> DataSet ---> DataTable ---> DataView ---> DataGrid

SqlCE

SQL Server Compact Edition (SqlCE) is a non-install, light-weight, local database that is embedded with a program.
SqlCE Databases are composed of a single .SDF file that can be stored anywhere that you can save and open it.

SqlCeConnection
Represents a unique connection to a data source.

SqlCeCommand
Queries the database for information (SELECT * FROM DataFile.SDF would grab all rows AND columns).

SqlCeDataAdapter
Serves as a bridge between a DataSet and data source. It is used for: retrieving data from AND saving data to, the data source.

It provides a bridge by using Fill to load data from the data source INTO the DataSet AND using Update to send changes made in the DataSet back TO  the data source.

Three Methods

The EXAMPLE below uses SqlCeCommand, SqlCeDataAdapter, and SqlCeConnection to select records from a data source, and dumps them in a DataSet.

CODE EXAMPLE:

// Connect to database
SqlCeConnection conn = new SqlCeConnection("Data Source = MyDatabase.sdf");

// Select data from the database
SqlCeCommand selectCmd = conn.CreateCommand();
selectCmd.CommandText = "SELECT * FROM DimEmployee";

// Dump data into a DataSet
SqlCeDataAdapter adp = new SqlCeDataAdapter(selectCmd);
DataSet ds = new DataSet();
adp.Fill(ds);

// Convert DataSet to DataView for WPF DataGrid ItemsSource
DataView dv = ds.Tables[0].DefaultView;

Displaying information stored in a .SDF file table goes something like this:

Data source  ------SqlCeDataAdapter.Fill-----> DataSet ------MyDataSet.Tables[0]-----> DataTable -------DataTable.DefaultView-----> DataView ------DataGrid.ItemsSource-----> Display data source in a WPF DataGrid