sql - Check if variable can be cast against a dynamic datatype -
i creating import application in vb.net sql server 2008 database. trying make import generic possible reduce maintenance in future. therefore gets available columns preset list of tables in can import into.
the main problem have gotten point doing error trapping. try check see whether value being imported castable data type of field in database. example, if want import date database mistakenly put address field instead, want pick , alert user.
so, have vb datatable same schema database table , value go datatable. below have (which not alot):
private sub setvalue(targetdatatable datatable, columnname string, value string) dim dbtype type = targetdatatable.columns(columnname).datatype ???? end sub
i have done research reflection still requires me define datatypes. there other ways of doing this?
don't think there way automatically type, according msdn there 18 types supported should manageable.
private sub setvalue(targetdatatable datatable, columnname string, value string) dim dbtype type = targetdatatable.columns(columnname).datatype dim valueint integer dim valuebln boolean if dbtype gettype(integer) andalso integer.tryparse(value, valueint) = false 'has error end if if dbtype gettype(boolean) andalso boolean.tryparse(value, valuebln) = false 'has error end if '... end sub
Comments
Post a Comment