Wednesday, December 19, 2007

Browsing a .SDF file (SQL Server CE database file)

If you are using SQL Server Compact Editition (SQL Server CE) and are producing .sdf files for use with your applicatoins, it is sometimes desireable to browse through a .sdf file's schema and data. Microsoft provides a nice tool for doing this, the SQL Server Management Studio Express. You must get Service Pack 2 or higher to have the SQL Server CE support.

It will let you select "SQL Server Compact Edition" for your Server Type and you can specify a .sdf file:










You can then browse the database's schema:






And you can perform queries on the data:







You can download the tool from Microsoft:

http://www.microsoft.com/downloads/details.aspx?FamilyID=6053c6f8-82c8-479c-b25b-9aca13141c9e&DisplayLang=en

Friday, December 14, 2007

Initialize char Array in C#

If you are used to initializing a char array in C++ like the following:


char mask[]={'a', 'b', 'c'};



There is a slight change when doing this in C#:

char[] mask=new char[] {'a', 'b', 'c'};


More examples:

http://www.java2s.com/Code/CSharp/Collections-Data-Structure/illustrateshowtoinitializearrays.htm

Wednesday, December 12, 2007

Testing to See if a Camera is Available on Windows Mobile Device

If you are trying to support a built in camera in your Windows Mobile Application, it is often useful to be able to test to see if the camera is availalble in the device. It is simple to do, but maybe not very obvious how to get to this property. Also, if you try to use the CameraCaptureDialog when there is no camera present, it can have unexpected results.

Dim cameraPresent As Boolean = _
CBool(Microsoft.WindowsMobile.Status.SystemProperty.CameraPresent)

Sunday, December 2, 2007

Iterating through a Dictionary Object's Items in VB.NET and C#

Iterating through a Dictionary Object's items may be more complicated than you think; however, with a few examples to go by it turns out to be pretty easy:

VB.NET

Dim DictObj As New Dictionary(Of Integer, String)

DictObj.Add(1, "ABC")
DictObj.Add(2, "DEF")
DictObj.Add(3, "GHI")
DictObj.Add(4, "JKL")

For Each kvp As KeyValuePair(Of Integer, String) In DictObj
Dim v1 As Integer = kvp.Key
Dim v2 As String = kvp.Value
Debug.WriteLine("Key: " + v1.ToString _
+ " Value: " + v2)
Next

C#

Dictionary<int, String> DictObj =
new Dictionary<int, String>();

DictObj.Add(1, "ABC");
DictObj.Add(2, "DEF");
DictObj.Add(3, "GHI");
DictObj.Add(4, "JKL");

foreach (KeyValuePair<int,String> kvp in DictObj)
{
int v1 = kvp.Key;
String v2 = kvp.Value;
Debug.WriteLine("Key: " + v1.ToString() +
" Value: " + v2);
}


It should also be pointed out that you can obtain a collection from the Dictionary Object for both Keys and Values using KeyCollection and ValueCollection:

VB.NET

Dim keyCollection As _
Dictionary(Of Integer, String).KeyCollection = _
DictObj.Keys

For Each key As Integer In keyCollection
Debug.WriteLine("Key: " + key.ToString())
Next

Dim valueCollection As _
Dictionary(Of Integer, String).ValueCollection = _
DictObj.Values

For Each value As String In valueCollection
Debug.WriteLine("Value: " + value.ToString())
Next


C#

Dictionary<int,String>.KeyCollection keyCollection=
DictObj.Keys;

foreach (int key in keyCollection)
{
Debug.WriteLine("Key: " + key.ToString());
}

Dictionary<int,String>.ValueCollection valueCollection = DictObj.Values;

foreach (String value in valueCollection)
{
Debug.WriteLine("Value: " + value.ToString());
}


For more examples see:

http://msdn2.microsoft.com/en-us/library/xfhwa508.aspx

Saturday, December 1, 2007

Debug.WriteLine in C#

If you are used to using Debug.WriteLine in VB.NET, it is sometimes a little confusing when you try to do it in C# and it doesn't work. The trick is to say:


using System.Diagnostics;


at the beginning of the C# app, then the Debug.WriteLine will work as you expect.


You can get more detailed information on this subject from:

http://support.microsoft.com/kb/815788