Skip to main content

Articles

Featured Products

Stay in touch using the DEVBUSS RSS feeds.
 

News

SQLCEDBView

Written by Michael Gledhill  [author's bio]  [read 20807 times]
Edited by Derek

Page 1  Page 2  Page 3  Page 4  Page 5 

So, as a .Net CF programmer, what can this application do to make our database coding easier ?

The most obvious change is that you can now type in and test the SQL queries that your program will run directly on your Desktop, and can make sure they are returning the fields and records that you really want.

However, there are two other tips I'd recommend for speeding up your .Net CF development time, when programming for SQLCE:

Suggestion 1

With SQLCE, only one application can have access to your database at once. So I recommend that, in Debug mode, whenever your code has to do any database work, it opens the connection to your SQLCE database, runs the query, then closes the connection.

This does cause a small performance hit, but has the advantage that after your code has added/changed your database's data, then straightaway you can use SQLCE Database Viewer to read in the table's data and check that your SQL command worked correctly.

Here's a simple example:

private void btnUpdate_Click(object sender, System.EventArgs e)
{
  RunSQL("UPDATE employees SET City='Toronto' WHERE EmployeeID=2");
}

public const string connectionString = "Data Source=\\My Documents\\Northwind.sdf";

private void RunSQL(string SQLcmd)
{
#if DEBUG
    // In DEBUG mode (only), open up the connection to the
    // SQLCE database each time we run an SQL command.
    SqlCeConnection m_conn;
    m_conn = new SqlCeConnection(connectionString);
    m_conn.Open();
#else
    // In Release mode, we'll use a Global SqlCeConnection
    // variable for an SQLCE connection that'll always
    // be kept open.
#endif

  // Run our SQL command.
  SqlCeCommand cmd = m_conn.CreateCommand();
  cmd.CommandText = SQLcmd;
  int rowsAffected = cmd.ExecuteNonQuery();

#if DEBUG
    m_conn.Close();
#endif
}

So in this example, our .Net CF program would run our UPDATE command, and we could then open/refresh the Employees table on our Desktop, to make sure that this record was updated successfully.

Previous Page  Next Page