in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

How to use CHAR's ?

Last post 09-01-2010 1:37 AM by Marc. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 08-31-2010 8:22 AM

    • Marc
    • Top 500 Contributor
    • Joined on 08-31-2010
    • Posts 6

    How to use CHAR's ?

    Hi,

    I created a table with a CHAR column in it, like this:

    CREATE TABLE ClientData(...., Status CHAR(1) NULL, ...)

    When inserting data i use a parameter with DbType.Byte.

    But when I read the data using a DataReader (SQLiteDataReader) and try the following code

    char x = dataReader.GetChar(10);

    i get:

    Specified cast is not valid.
    at System.Data.SQLite.SQLiteDataReader.VerifyType(Int32 i, DbType typ)
    at System.Data.SQLite.SQLiteDataReader.GetChar(Int32 i)

    I tried debugging this and I see that in the reader the column has an SQLiteType with Type=String and Affinity=Null and it is the Affinity=Null that is causing the exception.

    Can you tell me where i went wrong ?

    Thanks in advance.

  • 09-01-2010 1:37 AM In reply to

    • Marc
    • Top 500 Contributor
    • Joined on 08-31-2010
    • Posts 6

    Re: How to use CHAR's ?

    Ok I solved it. I forgot to test on dbnull :(

    if (!dataReader.IsDBNull(10))
         x = dataReader.GetChar(10);

Page 1 of 1 (2 items)
Powered by Community Server (Commercial Edition), by Telligent Systems