Results 1 to 3 of 3

Thread: [RESOLVED] Get decimal data type in stored proc and return to VB.NET

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,566

    Resolved [RESOLVED] Get decimal data type in stored proc and return to VB.NET

    I am struggling a little bit with getting a decimal datatype back from my stored procedure.

    In my table, I have columns whose datatype is decimal 9 (18,4). I have a stored procedure that gets a row from that table, and I have a parameter for the decimal column defined as:

    @mid AS decimal(18,4) OUTPUT

    Is that correct? First I had it as decimal(9) but I wasn't sure I was getting it back correctly.

    Then in my vb code, is this correct?
    Code:
                Dim p12 As New SqlParameter()
                p12.ParameterName = "@mid"
                p12.SqlDbType = SqlDbType.Decimal
                p12.Direction = ParameterDirection.Output
                command.Parameters.Add(p12)
    
                conn.Open()
    
                command.ExecuteNonQuery()
    
                mid = CDec(p12.Value)
    In the debugger, if I look at p12.Value it says 10D. The value is something more like 10.1356. Am I doing something wrong or is it the debugger's way of displaying it and how do I get the precision I want?

    Thanks.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Get decimal data type in stored proc and return to VB.NET

    look to see if there is a Precision (set it to 18) and a NumericScale (set to 4) on the parameter object and set them before adding it to the colleciton.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,566

    Re: Get decimal data type in stored proc and return to VB.NET

    Thank you for the reply, techgnome.

    For various reasons I changed my stored procedure to return a row rather than a parameter and it seemed easier to get the decimal value that way also. They are coming back to my program and going in my grid just as I want them!

    Have a nice day and thanks for taking the time to help out.

    Marlene

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width