Question: SQL Server 6.5, VB5 
Author Message
 Question: SQL Server 6.5, VB5

I am using SQL Server 6.5 and VB5 with ADO.

I am storing data items in the SQL Server table as money. From an ADO
recordset, I want to fill a user defined data type with a variable to
contain the money field from the table. I've declared the UDT item as
CURRENCY, DOUBLE, and VARIANT. Variant is the only one where I do not get a
"Type Mismatch" error when assigning the money value from the table to the
UDT item.

I am doing this:

TYPE udtSvc
    svc_id As String * 3
    svc_fee As Double
END TYPE

the table is as such

svc_id    char(3)
svc_fee  money(8,19,4)

the assignment is

With RSSvc
    udtSvc.svc_id = !svc_id
    udtSvc.svc_fee = !svc_fee
end with

What am I doing wrong?

Thanks for any help,

Michael D Jackson



Wed, 04 Apr 2001 03:00:00 GMT  
 Question: SQL Server 6.5, VB5
I've played with this problem a little more and found out the problem is
encountered when I have a <NULL> in the table column. I need the <NULL>
value... it indicates this item is not used, or unknown.

I've tried to assign the value of the column from the ADO recordset to a
udt, but get "invalid use of null" errors. I've appended a "" (null string),
but get a type mismatch.

What gives?

How can I allow use of <NULL> in a table column, assign it to a variable and
allow the textbox to be loaded with the value from the UDT variable without
raising all these errors.?

Thanks

Michael D Jackson



Wed, 04 Apr 2001 03:00:00 GMT  
 Question: SQL Server 6.5, VB5
Michael,

Null values cannot be assigned to "typed" VB variables. You must use
variants or
Substitute a Null value by some default that indicates the value was null.
You could then
write a function ReplaceNull as follows --

Function ReplaceNull(ByVal varIN As Variant, ByVal constValue As Variant) As
Variant
    On Error Resume Next

    If Trim$(varIN & "") = "" Then
        ReplaceNull = constValue
    Else
        ReplaceNull = Trim(varIN)
    End If
End Function

Then in your code, if testudt.TestMoney is a Currency, Use --
testudt.TestMoney = CCur(ReplaceNull(rs!MoneyColumn, -999.99))

where -999.99 is a default that indicates a Null condition.

-Jay

Quote:

>I've played with this problem a little more and found out the problem is
>encountered when I have a <NULL> in the table column. I need the <NULL>
>value... it indicates this item is not used, or unknown.

>I've tried to assign the value of the column from the ADO recordset to a
>udt, but get "invalid use of null" errors. I've appended a "" (null
string),
>but get a type mismatch.

>What gives?

>How can I allow use of <NULL> in a table column, assign it to a variable
and
>allow the textbox to be loaded with the value from the UDT variable without
>raising all these errors.?

>Thanks

>Michael D Jackson



Wed, 04 Apr 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Locking in VB5 and SQL Server 6.5 using stored procs

2. Stored Procedures with VB5/SQL Server 6.5

3. VB5: Updating recordset on MS SQL-Server 6.5

4. VB5 with SQL Server 6.5

5. Using VB5 and Sql Server 6.5

6. a sample application of VB5.0 and SQL Server 6.5

7. VB5 with SQL Server 6.5

8. connecting to MS SQL Server 6.5 using VB5

9. SQL Server 6.5 and VB5

10. How to..Using VB5 with Sql server 6.5

11. VB5 EE, SQL/Server 6.5, Win NT

12. Error 20532 Crystal 6, SQL Server 6.5 and VB5

 

 
Powered by phpBB® Forum Software