Results 1 to 4 of 4

Thread: problem with code

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    12

    problem with code

    i have a database shown on VB 2008 showing music information. i am trying to show the track with the greatest number of sales however it is only displaying the current information on the screen (i am showing the access database in multiple text boxes) rather than searching the database.

    this is the section of code i am struggling with:

    Code:
    Private Sub Btntopseller_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btntopseller.Click
            Dim index, largest As Integer
            Dim found As Boolean
            Dim topselling As String
    
    
    
    
    
    
            largest = CInt(mytable.Rows(row)(3))
    
            found = False
            index = 0
            topselling = mytable.Rows(row)(1)
            While (found = 0) And (index < largest)
    
                If CStr(mytable.Rows(row)(3)) = largest Then
                    found = True
                    MessageBox.Show("Tune Found")
                    TextBox1.Text = topselling
                Else
                    index = index + 1
    
                End If
    
            End While
       End Sub
    End Class
    i also would like to add to this, i would like the user to be able to select a year from a list box to show the track with the greatest number of sales in that year. any ideas would be great.

    thankyou
    andy

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: problem with code

    Why are you trying to walk the rows of a datatable when you should just be quering the database for the exact information you want

    --All sales for a year
    Select Sum(sales) from tablename where Year(dateSold) = 2009
    --Top 10 sales by book in a year
    Select TOP 10 BookId,Sum(Sales) from tableName where Year(dateSold) = 2009 GROUP BY BookId

    and so on
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    12

    Re: problem with code

    This sounds really helpful however i am only an amateur in programming and have not yet looked at queries.

    are there any websites that could walk me through how to create a query?

  4. #4
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: problem with code

    jcilhinney has a code bank article that will walk you through most of what you need to know about using databases with vb.net, however he stops short of explaining how SQL queries are constructed (ie SQL syntax). For that, I'd suggest looking at this w3schools tutorial.

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