Thursday, 15 July 2010

c# - Query to SQLite returning signed int16 but was defined as unsigned -



c# - Query to SQLite returning signed int16 but was defined as unsigned -

i using sqlite ado.net, .net v4.0 binaries exact.

i have nail problem while trying populate info of class based on contents of extract database.

the reflection code:

var type = this.gettype(); var properties = type.getproperties(); foreach(var property in properties) { property.setvalue(this, row[property.name]); }

however throws exception: object of type 'system.int64' cannot converted type 'system.uint16'.

the value trying populate ushort. in sql generate table, column defined 'unsigned smallint' understanding should same c# ushort.

the creation sql-

create table [monsters] ( [monsterid] unsigned smallint not null unique, [monstername] varchar(50) not null, [elementmask] unsigned tinyint not null, [str] unsigned tinyint not null, [dex] unsigned tinyint not null, [int] unsigned tinyint not null, [con] unsigned tinyint not null, [spd] unsigned tinyint not null, [imagesetid] unsigned smallint null )

removing 'unsigned' throws exception instead: object of type 'system.int16' cannot converted type 'system.uint16'. expected given signed/unsigned mismatch.

inspecting row in debug mode shows expected data. http://i.stack.imgur.com/7ayts.png

not quite sure going on help appreciated.

thanks.

sqlite uses dynamic typing; column type ignored, , type of returned value depends on value itself.

use propertytype convert value right type.

c# sqlite reflection casting

No comments:

Post a Comment