Last post Dec 04, 2009 03:37 PM by SynergyNT
Dec 04, 2009 12:42 PM|gymrat29|LINK
This is probably pretty simple but having trouble wrapping my head around it. Working on using a SQL database to store the number of times someone downloads a file. Kind of like what you see on other sites where it says "Downloaded 325 times". I created
a database just with an ID column, and a hits column. The hits column will store the number of clicks on that link to download a PDF and inserting the count into the database. I've looked through a bunch of threads but nothing that just covers this that I
found so far? I'm using ASP.NET VB in this programming.
Thanks in advance!
.net vb clicks count
Dec 04, 2009 01:31 PM|SynergyNT|LINK
I would think you could handle this in the click event for your download button. You would be assuming that the download completed successfully, but just use ADO.NET to connect to your DB and set the count column to itself plus 1 for the ID associated with
Dec 04, 2009 02:52 PM|gymrat29|LINK
Hi Synergy, thanks for responding.
Well, I did figure on a click event already but putting it all together is what I'm talking about (query etc.)
Do you have any code example? Would I use a sqlDataReader in the code?
Right now I have:
'connect to database
'Update the database with clicked number
clickLink += clickLink
Dec 04, 2009 03:37 PM|SynergyNT|LINK
Actually you would use a combination of a SqlConnection and a SqlCommand and then you would use the ExecuteNonQuery method of your command object to actually update the DB. Here is an example of updating the DB.
' You could link this to a connection in your web.config as well.
Dim connStr As String = "Server=(local);Database=Northwind;Integrated Security=SSPI"
Dim cmdStr As String = "UPDATE tbDownloads SET Count = Count + 1 WHERE ID = @DownloadID"
Dim conn As SqlConnection = New SqlConnection(connStr)
Dim cmd As SqlCommand = New SqlCommand(cmdStr, conn)
' Replace the DownloadID for the second argument with whatever variable or property you are using to determine the file that is being downloaded.