I recently came across an issue with type conversion that I would like explaining to me.
We had a SQL 2000 stored procedure that had a parameter declared as:
@event_id numeric(9,0)
We used the VB.NET SQLParameter class to send the data to the procedure:
Public Sub New( _
ByVal parameterName As String, _
ByVal dbType As SqlDbType, _
ByVal size As Integer, _
ByVal direction As ParameterDirection, _
ByVal isNullable As Boolean, _
ByVal precision As Byte, _
ByVal scale As Byte, _
ByVal sourceColumn As String, _
ByVal sourceVersion As DataRowVersion, _
ByVal value As Object _
)
like so:
param = New SqlParameter("@event_id",
SqlDbType.Decimal,
0,
ParameterDirection.Input,
False,
9,
0,
"",
DataRowVersion.Default,
CSng(strEventID))
This was working fine until recently, when suddenly the value arriving at the stored procedure didn't match the value we were sending it. I.E. we sent a value of 10207933, but the value arriving at the spoc was 10207930.
We fixed it by using CDbl instead of CSng, but I want to know why, as a Single can hold values up to 3.402823e38, far more than the value being converted.
Can anyone explain this to me please?
Many Thanks,
Janine
Start Free Trial