Looking into System.Data.DbType there is no SqlVariant type there. SqlDataReader, for example, provides the GetString method for reading into string variable. What is the appropriate way to retrieve data from the database field of type sql_variant, presumably into object?
The aim is to read data stored as sql_variant type in database. Not to assign the value into variable of object type. I mentioned object type variable because I thing the sql_variant, if possible, would go into such type.
If you want to put the data into a variable of type object then (simplified):
object result = null;
result = reader["columnNameGoesHere"];
Should do the trick.
There's also a good explanation of the various different methods of retrieving the contents of a given columns current record in this DevHood tutorial. The summary table of data type mappings at the end may come in handy too!
Sql_Variant is of type object.
Microsoft Docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With