Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6150057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:33:28+00:00 2026-05-23T19:33:28+00:00

I’ve got a column in my Microsoft SQL CE 3.5 SP2 database called Type

  • 0

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}.

enter image description here

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:33:30+00:00Added an answer on May 23, 2026 at 7:33 pm

    SQL doesn’t have a char data type. All it has are strings — char(n), varchar(n), nchar(n) and nvarchar(n). You’ll notice that char is conspicuous by its absence in the conversion chart at http://msdn.microsoft.com/en-us/library/cc716729.aspx

    If you are using a SqlDataReader, you can retrieve your char value as an array of chars via the SQLDataReader’s GetChars() method:

    SqlDataReader sdr = ...
    ...
    int    ordinalColumnNumber = 3 ;
    char[] buffer              = new char[1] ;
    int    charCount           = sdr.GetChars( ordinalColumnNumber , 0 , buffer , 0 , buffer.Length ) ;
    if ( charCount != buffer.Length ) throw new InvalidOperationException() ;
    char value = buffer[0] ;
    

    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 from char to short or ushort, so a comparison should work as you expect:

    public bool Test( char value , short expected )
    {
      return ( value == expected ) ;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.