0

I have a SqlMetaData array defined as:

SqlMetaData[] _TvpSchema = new SqlMetaData[]{
     new SqlMetaData("Duration", SqlDbType.Float)
};

And SqlDataRecord for it as :

SqlDataRecord _DataRecord = new SqlDataRecord(_TvpSchema);

And filling this record as:

_DataRecord.SetFloat(4, (float)obj.Duration);

Where obj.Duration is decimal type and has value as 0. I am getting Exception of Invalid Cast at the above line. I tried Convert.ToSingle also, but got the same error. What I might be doing wrong in this case?

1 Answer 1

2

A SQL Float is a .Net double according to SqlDbType documentation. If you really need to use a .Net float, use the SQL Real type, otherwise, just use SetDouble and cast your decimal to double.

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

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.