mj2008
04-29-2008, 09:11 PM
I have an audio upload button and as the user uploads audio points will be added to their UserID in a table called Users but im having a few problems.
This is the code behind the upload button:
Imports System.Data
Imports System.Data.SqlClient
Partial Class Upload2
Inherits System.Web.UI.Page
Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
' Update the Users Points
updateUserPoints(Membership.GetUser().ProviderUserKey)
' limitation of maximum file size
Dim intFileSizeLimit As Integer = 4048000
' get the full path of your computer
Dim strFileNameWithPath As String = FileUpload1.PostedFile.FileName
' get the extension name of the file
Dim strExtensionName As String = System.IO.Path.GetExtension(strFileNameWithPath)
' get the filename of user file
Dim strFileName As String = System.IO.Path.GetFileName(strFileNameWithPath)
'get the file size
Dim intFileSize As Integer = FileUpload1.PostedFile.ContentLength
'Restrict the user to upload only .mp3 or .wma file
strExtensionName = strExtensionName.ToLower()
If (strExtensionName.Equals(".mp3") Or strExtensionName.Equals(".wma") Or strExtensionName.Equals(".m4a") Or strExtensionName.Equals(".aif")) Then
'Rstrict the File Size
If (intFileSize < intFileSizeLimit) Then
'upload the file on the server
FileUpload1.PostedFile.SaveAs(Server.MapPath(("Uploads/" & strFileName)))
lbloutput.Text = "Upload Succeeded"
pnMediaPlayer.Controls.Add(New LiteralControl("<object id='VIDEO' width='300px' style='height: 60px;' classid = 'CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6' type='application/x-oleobject'>" & _
"<param name='URL' value='" & Request.ApplicationPath.TrimEnd("/") & "/Uploads/" & strFileName & "'/>" & _
"<param name='SendPlayStateChangeEvents' value='true'/>" & _
"<param name='AutoStart' value='true'/>" & _
"<param name='uiMode' value='full'/>" & _
"<param name='PlayCount' value='1'/>" & _
"<param name='stretchToFit' value='true'/>" & _
"<param name='Volume' value='80'/>" & _
"<param name='enableContextMenu' value='false'/>" & _
"<param name='windowlessVideo' value='false'/>" & _
"</object>"))
Else
lbloutput.Text = "Too Big,Upload smaller file."
End If
Else
lbloutput.Text = "Only .mp3.wma or .aif file are allowed!"
lbloutput.ForeColor = System.Drawing.Color.Red
End If
End Sub
Private Sub updateUserPoints(ByVal Band As String)
'Create a connection to the SQL Server.
Using MyConnection = New SqlConnection("Data Source=mssql.ittraleedemo.com;Initial Catalog=T001035_soundwave;User ID=T001045_sheena200;Password=8318183Q")
MyConnection.Open()
Using myCommand As New SqlCommand("updateUserPoints", MyConnection)
myCommand.CommandType = CommandType.StoredProcedure
myCommand.Parameters.Add("@UserID", SqlDbType.UniqueIdentifier, 50).Value = "+3"
Dim rowAffected As Integer = myCommand.ExecuteNonQuery()
Response.Write(String.Format("{0} row affected", rowAffected))
End Using
End Using
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lblUserId.Text = Membership.GetUser().ProviderUserKey
End Sub
End Class
updateUserpoints is a stored procedure
ALTER PROCEDURE updateUserPoints
@UserID uniqueidentifier
AS
/* SET NOCOUNT ON */
UPDATE Users
Set Points = Points +3
WHERE BandArtist = @UserID
RETURN
An error keeps popping up when i run it.
Its probably something simple but seeing as im not great with the ASP.net package im finding it very confusing. Any help would be greatly appreciated.
This is the code behind the upload button:
Imports System.Data
Imports System.Data.SqlClient
Partial Class Upload2
Inherits System.Web.UI.Page
Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
' Update the Users Points
updateUserPoints(Membership.GetUser().ProviderUserKey)
' limitation of maximum file size
Dim intFileSizeLimit As Integer = 4048000
' get the full path of your computer
Dim strFileNameWithPath As String = FileUpload1.PostedFile.FileName
' get the extension name of the file
Dim strExtensionName As String = System.IO.Path.GetExtension(strFileNameWithPath)
' get the filename of user file
Dim strFileName As String = System.IO.Path.GetFileName(strFileNameWithPath)
'get the file size
Dim intFileSize As Integer = FileUpload1.PostedFile.ContentLength
'Restrict the user to upload only .mp3 or .wma file
strExtensionName = strExtensionName.ToLower()
If (strExtensionName.Equals(".mp3") Or strExtensionName.Equals(".wma") Or strExtensionName.Equals(".m4a") Or strExtensionName.Equals(".aif")) Then
'Rstrict the File Size
If (intFileSize < intFileSizeLimit) Then
'upload the file on the server
FileUpload1.PostedFile.SaveAs(Server.MapPath(("Uploads/" & strFileName)))
lbloutput.Text = "Upload Succeeded"
pnMediaPlayer.Controls.Add(New LiteralControl("<object id='VIDEO' width='300px' style='height: 60px;' classid = 'CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6' type='application/x-oleobject'>" & _
"<param name='URL' value='" & Request.ApplicationPath.TrimEnd("/") & "/Uploads/" & strFileName & "'/>" & _
"<param name='SendPlayStateChangeEvents' value='true'/>" & _
"<param name='AutoStart' value='true'/>" & _
"<param name='uiMode' value='full'/>" & _
"<param name='PlayCount' value='1'/>" & _
"<param name='stretchToFit' value='true'/>" & _
"<param name='Volume' value='80'/>" & _
"<param name='enableContextMenu' value='false'/>" & _
"<param name='windowlessVideo' value='false'/>" & _
"</object>"))
Else
lbloutput.Text = "Too Big,Upload smaller file."
End If
Else
lbloutput.Text = "Only .mp3.wma or .aif file are allowed!"
lbloutput.ForeColor = System.Drawing.Color.Red
End If
End Sub
Private Sub updateUserPoints(ByVal Band As String)
'Create a connection to the SQL Server.
Using MyConnection = New SqlConnection("Data Source=mssql.ittraleedemo.com;Initial Catalog=T001035_soundwave;User ID=T001045_sheena200;Password=8318183Q")
MyConnection.Open()
Using myCommand As New SqlCommand("updateUserPoints", MyConnection)
myCommand.CommandType = CommandType.StoredProcedure
myCommand.Parameters.Add("@UserID", SqlDbType.UniqueIdentifier, 50).Value = "+3"
Dim rowAffected As Integer = myCommand.ExecuteNonQuery()
Response.Write(String.Format("{0} row affected", rowAffected))
End Using
End Using
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lblUserId.Text = Membership.GetUser().ProviderUserKey
End Sub
End Class
updateUserpoints is a stored procedure
ALTER PROCEDURE updateUserPoints
@UserID uniqueidentifier
AS
/* SET NOCOUNT ON */
UPDATE Users
Set Points = Points +3
WHERE BandArtist = @UserID
RETURN
An error keeps popping up when i run it.
Its probably something simple but seeing as im not great with the ASP.net package im finding it very confusing. Any help would be greatly appreciated.