c# - Impossible to add a User-Defined-Data Type parameter to my query -
i'm trying use user-defined-data type c# , sql server 2008 have exception raised when command.executereader() executed.
string qyery = "select * product isavailableproduct < @param"; sqlcommand command = new sqlcommand(qyery, conn); sqlparameter param = new sqlparameter("@param", sqldbtype.structured); param.udttypename = "mybolean"; param.sqldbtype = sqldbtype.structured; param.value = 1; command.parameters.add(param); sqldatareader reader = command.executereader();
the raised exception :
failed convert parameter value int32 ienumerable``1.
what's wrong in code ?
edit :
if change sqldbtype udt, have exception : specified type not registered on target server.system.int32, mscorlib, version=2.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089.
if set dbtype property int (which base type of "mybolean") result exception failed convert parameter value int32 ienumerable
1.`` raised too.
edit :
i modified title because in sql server 2008, it's "user define data type" , no "user defined types"
the sqldbtype
enumeration value structured
used indicate you're passing around table value parameter, why you're getting error message you're getting value you're passing in integer, not "list of something" use tvp.
you need set param.sqldbtype
based on underlying datatype mybolean
suspect bit
or int
.
Comments
Post a Comment