I’ve got a column in my Microsoft SQL CE 3.5 SP2 database called Type that needs to store a single character.
To do this, I have formatted the column as nchar(1), and storing the data works fine.
However, whenever I attempt to fill a DataTable using Visual Studio 2010, the Type column values are stored as string values.
This really only causes havoc whenever I try to use one of our company methods to test if a given data row has changed. The value stored in memory (a character) is never equal to the value read back from the database (since it is a different data type).
Rather than write a special routine that tests every column to see if it is a char data type and cast that, is there a different SQL data type that I should be assigning to the table’s Column?
The list of available columns appears to be {bigint, binary, bit, datetime, float, image, int, money, nchar, ntext, numeric, nvarchar, real, rowversion, smallint, tinyint, uniqueidentifier, varbinary}.

Solved
To determine if my In Memory data had changed from the SQL CE Table, I used the following routine:
// Class RowData
// private List<CellData> cellList;
public bool Changed(DataTable table) {
int index = RowIndex(table);
if (-1 < index) {
DataRow row = table.Rows[index];
foreach (DataColumn col in table.Columns) {
if (!String.IsNullOrEmpty(col.ColumnName)) {
bool found = false;
foreach (var cell in cellList) {
if (cell.ColumnName == col.ColumnName) {
object o = row[cell.ColumnName];
if (col.DataType != typeof(string)) {
if (!cell.Value.Equals(o)) {
return true; // this fails on a Char.value 'C' != "C"
}
} else if (col.MaxLength != 1) {
if (!cell.Value.Equals(o)) {
return true; // this fails on a Char.value 'C' != "C"
}
} else {
string str = o.ToString();
if (!cell.Value.Equals(str[0])) {
return true;
}
}
found = true;
}
if (found) {
break;
}
}
}
}
return false;
}
return true;
}
Feel free to critique anything in my code. I hate hearing I don’t do something the best way, but it always spurs growth in my abilities.
SQL doesn’t have a
chardata type. All it has are strings —char(n),varchar(n),nchar(n)andnvarchar(n). You’ll notice thatcharis conspicuous by its absence in the conversion chart at http://msdn.microsoft.com/en-us/library/cc716729.aspxIf you are using a SqlDataReader, you can retrieve your char value as an array of chars via the SQLDataReader’s
GetChars()method:That’s probably as close as your going to get. The alternative would be to store your single char as a
smallint. The C# language specification defines an implicit conversion fromchartoshortorushort, so a comparison should work as you expect: