Results 1 to 7 of 7

Thread: Return Respective Type

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026

    Return Respective Type

    Hello Ladies and Gents,

    I created small class to make my data access easier on this project (why else should we have classes if not to make our lives a little more sane and keep our hair longer???).

    The only snag I have run into is the following:

    I would like for the code snippet below to be changed so that it returns the data in whatever datatype it was formatted in within my Access DB...

    I'm sure this has been done before and that one of you will probably deside to doze of as you answer it, but it's been buggin' me just the same.

    VB Code:
    1. Public Function GetVal(ByVal Field As String) As String
    2.         If IsNothing(RS) Then Exit Function
    3.  
    4.         Try
    5.             Return Convert.ToString(RS.Fields(Field).Value)
    6.         Catch ex As Exception
    7.             Return ""
    8.         End Try
    9.     End Function

    Thanks in advance,

    Squirrelly1
    Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?

  2. #2
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    Squirrelly1,

    Hate to answer your question with a question, but what kind of object is RS?
    Also, how do you know which row/record you are on?

    John

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You would use the generic type Object:
    VB Code:
    1. Public Function GetVal(ByVal Field As String) As Object
    2.         If IsNothing(RS) Then Return
    3.  
    4.         Try
    5.             Return RS.Fields(Field).Value
    6.         Catch ex As Exception
    7.             Return
    8.         End Try
    9.     End Function

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026
    John,

    The object is an ADODB Recordset.

    Edneeis,

    Thanks, I'll give it a shot.

    ,

    Squirrelly1
    Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Why are you using an ADODB Recordset in .NET?

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026
    What should I use in .Net? I'm just used to having implemented ADODB this way... Is there a better one?

    Squirrelly1
    Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Yes in .NET there are DataReaders or DataSets to replace the Recordset and they work much better. Poke around here for an example or check out the here:

    http://samples.gotdotnet.com/quickstart/winforms/

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