3

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.

2 Answers 2

4

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!

Sign up to request clarification or add additional context in comments.

Comments

1

Sql_Variant is of type object.

Microsoft Docs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.