|
-
Apr 5th, 2010, 11:53 AM
#1
Thread Starter
New Member
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
-
Apr 5th, 2010, 12:00 PM
#2
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
-
Apr 5th, 2010, 12:08 PM
#3
Thread Starter
New Member
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?
-
Apr 5th, 2010, 12:16 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|