Advertisement

07.16.2007 at 09:00AM PDT, ID: 22699007
[x]
Attachment Details

Explanation of VB to SQL type conversion please

Asked by janineo in .NET, MS SQL Server

Tags: sql, sqldbtype, type

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
 
 
[+][-]07.16.2007 at 09:22AM PDT, ID: 19497107

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET, MS SQL Server
Tags: sql, sqldbtype, type
Sign Up Now!
Solution Provided By: Dxpert
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.16.2007 at 09:27AM PDT, ID: 19497147

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.16.2007 at 11:35AM PDT, ID: 19498263

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.16.2007 at 11:41AM PDT, ID: 19498342

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32