PDA

View Full Version : Result Output


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.

jleone
04-29-2008, 10:22 PM
What is the error that you are getting? Can you post the exact error message? The only thing I see by a quick glance is "Membership.GetUser().ProviderUserKey" - what does this return. You pass this value to your updateUserPoints function. The function wants to accept a string variable. Is this "Membership.GetUser().ProviderUserKey" a string value? Need a little more info.

mj2008
04-29-2008, 10:27 PM
The Error is

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 71:
Line 72: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Line 73: lblUserId.Text = Membership.GetUser().ProviderUserKey
Line 74: End Sub
Line 75: End Class

jleone
04-30-2008, 02:30 PM
Yup, your "Membership" class has not been instantiated. Is this a class you created in a class library file. If so, you need to instantiate a new instance of the object before you can use any of it properties, subs, or functions.

Declare at the top of your page a new variable (Private Member as Membership).

Then instantiate the object ( Member = New Membership() ).

Then call Member.GetUser().ProviderUserKey