CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2012
    Posts
    46

    [RESOLVED] (VS2010) Multi-Field Mathematical SQL Query

    While I do know how to create a mathematical SQL query I am having difficulties with creating a statement involving multiple rows, each row chose by one or more attributes selected in the GUI of my program. To get a better idea of my purpose:

    I have a page with 4 different part types. Each part type has multiple selectable values that are chosen by the user. When all values of each part type are chosen a total is calculated (this is the total between all 4 part types). All prices are in the same data table.

    I have an idea of how this must be done (Looped SQL query) but I have never dealt with this before and would appreciate a nudge in the right direction.

    Thanks for any leads you may offer.

  2. #2
    Join Date
    Jul 2012
    Posts
    46

    Re: (VS2010) Multi-Field Mathematical SQL Query

    Here is what I have for the function so far:

    Code:
    Public Function GetPrice(ByVal Part_Number As String) As Double
            Try
                Using udtConn As New SqlConnection(sBoMConnectionString)
    
                    Dim daPrice As New SqlDataAdapter(New SqlCommand("SELECT Last_Quote_Amt FROM Part Where Part_Nbr = '" & Part_Number & "'", udtConn))
                    Dim dsPrice As New DataSet
    
                    dsPrice.Tables.Add("Part")
                    daPrice.Fill(dsPrice.Tables("Part"))
    
                    Me.BoMDataSetBindingSource.DataSource = dsPrice.Tables("Part")
                    daPrice.Fill(dsPrice)
    
                    Return dsPrice.Tables("Part").Rows(0).Item("Last_Quote_Amt")
    
                End Using
            Catch ex As Exception
                'An error occured while pulling data
            End Try
        End Function

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

Featured