Results 1 to 7 of 7

Thread: Using a function in a dataset before returning it

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Using a function in a dataset before returning it

    I have a field in a dataset that I would like to run through a function and then add the result to the dataset before returning it to the sub.

    Right now I am getting the dataset, putting the ZipCodes into an array and then getting my distance calc after the fact. This works ok but it would be far better to have included with the original dataset.

    This is what I am doing now.
    VB Code:
    1. Dim getZip As String = txtZip.Text
    2.         Dim getRad As Integer = RadioButtonList1.SelectedValue
    3.         Dim myDS As DataSet = GetUE_ZipRadius(getZip, getRad)
    4.         DataList1.DataSource = myDS
    5.         DataList1.DataBind()
    6.  
    7.         With myDS.Tables("ZipCodes")
    8.             Dim zipCodesA(.Rows.Count - 1) As String
    9.             For i As Integer = 0 To .Rows.Count - 1
    10.                 zipCodesA(i) = CStr(DirectCast(.Rows(i).Item("ueZip"), Integer))
    11.                 LookUpZipCode(getZip, zipCodesA(i))
    12.                 ListBox1.Items.Add(Format(CalcDistance(), "F").ToString)
    13.             Next
    14.         End With
    15.  
    16.         myDS.Dispose()

    Is it possible to the (Format(CalcDistance(), "F").ToString) before hand and have the distances added as a column to the dataset?

    Oh yea the dataset code looks like this
    VB Code:
    1. Dim LowLatitude As Double = iStartLat - LatRange
    2.         Dim HighLatitude As Double = iStartLat + LatRange
    3.         Dim LowLongitude As Double = iStartLon - LonRange
    4.         Dim HighLongitude As Double = iStartLon + LonRange
    5.  
    6.         Dim strSelect2 As String = _
    7.             "Select ueStore, ueAddress, ueCity, ueState, " & _
    8.             "ueZip, uePhone From queUncEdsZCodes " & _
    9.             "Where Latitude <=" & HighLatitude & _
    10.             "And Latitude >=" & LowLatitude & _
    11.             "And Longitude <=" & HighLongitude & _
    12.             "And Longitude >=" & LowLongitude
    13.  
    14.         Dim Cmd2 As New OleDbDataAdapter(strSelect2, conn)
    15.         Dim ds As New DataSet
    16.         Cmd2.Fill(ds, "ZipCodes")
    17.  
    18.         Return ds
    Last edited by FastEddie; Mar 28th, 2006 at 08:09 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Using a function in a dataset before returning it

    What database are you using? Many databases will allow you to create functions which you could call as part of your SQL code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Re: Using a function in a dataset before returning it

    Currently it is Access 2000 but I (think) could easily change to SQL 2005 Express if that could handle this task better.
    Last edited by FastEddie; Mar 28th, 2006 at 08:11 AM.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Using a function in a dataset before returning it

    SQL Server will be a better bet if you want to perform calculations in your SQL. It will let you create your own functions. Access has some built in SQL functions but I don't think it will let you create your own. I'm no database guru so I don't know all the details so it would be worth investigating further. Perhaps a post in the Database forum could give you a quick answer as to how easy it would be in each case.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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

    Re: Using a function in a dataset before returning it

    Keep in mind that databases are be suited for data storage and retrieval. They are poor performers when it comes to processing logic. It may turn out (depending on how complex you calculations are), that it is more efficient to continue to use VB as the number cruncher like you currently are.

    -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??? *

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Using a function in a dataset before returning it

    Quote Originally Posted by techgnome
    Keep in mind that databases are be suited for data storage and retrieval. They are poor performers when it comes to processing logic. It may turn out (depending on how complex you calculations are), that it is more efficient to continue to use VB as the number cruncher like you currently are.

    -tg
    Excellent point. I invoke my aforementioned non-database-guru status when I say that I have no idea how efficient using database functions would be. I guess they're useful when you're using the database directly, but when you have a powerful front-end like something written in VB.NET then maybe you would be best to stick to what you have. It could be a fun exercise to find out though, depending on your definition of fun.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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

    Re: Using a function in a dataset before returning it

    Yeah... trust me.... it's not "fun".... as some one who just did a bunch of optimizations on some SQL stuff.... we ended up pulling all of the logic processing out of the SP and putting it into VB... a 130 minute process dropped to 5 minutes!

    -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??? *

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