Copied your whole code, hooded, but it didn't work for some reason, can't see a reason as to why not. When I clicked to go to the vote page, the message didn't come up. Then when I clicked on the submit votes button it gave me the original error message.
Well, that's what I would love to do, but in some other thread, someone told me you can't use MessageBox (or MsgBox) for project. They said when it's saved on a server and run, it will only show up on the server, so the client side won't see anything. I
don't know if that's true as I am yet to load a project on a server and try.
Uhhh no I haven't written the code for the hasvoted function lol
Haha good job. I'm not sure how you set up the whole system of keeping track who has voted, so unless you can write the code yourself, explain a little :)
function hasvalues() as boolean
Dim currentUser As MembershipUser = Membership.GetUser()
Dim currentUserId As Guid = CType(currentUser.ProviderUserKey, Guid)
Dim retvalue As Boolean = false
Dim connectionString As String = ConfigurationManager.ConnectionStrings("SecurityTutorialsConnectionString").ConnectionString
Dim insertSql As String = "SELECT COUNT(*) FROM Awards WHERE UserId = @UserId"
Using myConnection As New SqlConnection(connectionString)
Dim myCommand As New SqlCommand(insertSql, myConnection)
myCommand.Parameters.AddWithValue("@UserId", currentUserId)
Try
myConnection.Open()
Dim val = mycommand.executescalar()
if val isnot nothing then
if int32.parse(val) > 0 then
retvalue = true
end if
end if
myConnection.Close()
Catch ex As Exception
throw ex
End Try
End Using
return retvalue
end function
Oh wow, I forgot you already showed the query to insert stuff...that way we can just take stuff out of the database! This will be put in your hasvoted() function:
Dim currentUser As MembershipUser = Membership.GetUser()
Dim currentUserId As Guid = CType(currentUser.ProviderUserKey, Guid)
Dim connectionString As String = ConfigurationManager.ConnectionStrings("SecurityTutorialsConnectionString").ConnectionString
Dim insertSql As String = "SELECT * FROM Awards WHERE UserID='" & currentUserId & "'"
Using myConnection As New SqlConnection(connectionString)
Dim myCommand As New SqlCommand(insertSql, myConnection)
Dim reader As New SqlReader = myCommand.ExecuteReader()
If(Not reader.HasRows())
Return False
Else
Return True
End If
tottenham_ru...
Member
11 Points
87 Posts
Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.A...
Jun 02, 2010 08:31 PM|LINK
Copied your whole code, hooded, but it didn't work for some reason, can't see a reason as to why not. When I clicked to go to the vote page, the message didn't come up. Then when I clicked on the submit votes button it gave me the original error message.
Thanks,
Mike
rsw20
Member
548 Points
112 Posts
Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.A...
Jun 02, 2010 08:34 PM|LINK
did you write code for hasvoted function?
hoodedperson...
Star
12950 Points
3196 Posts
Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.A...
Jun 02, 2010 08:39 PM|LINK
Hah yeah that's what I was going to ask!
oaksong
Member
10 Points
32 Posts
Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.A...
Jun 02, 2010 08:41 PM|LINK
How about :
Try
{code}
Catch ex as exception
messagebox ("Oops, sorry, you can't vote twice")
End Try
tottenham_ru...
Member
11 Points
87 Posts
Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.A...
Jun 02, 2010 08:42 PM|LINK
Uhhh no I haven't written the code for the hasvoted function lol
hoodedperson...
Star
12950 Points
3196 Posts
Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.A...
Jun 02, 2010 08:44 PM|LINK
Well, that's what I would love to do, but in some other thread, someone told me you can't use MessageBox (or MsgBox) for project. They said when it's saved on a server and run, it will only show up on the server, so the client side won't see anything. I don't know if that's true as I am yet to load a project on a server and try.
hoodedperson...
Star
12950 Points
3196 Posts
Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.A...
Jun 02, 2010 08:45 PM|LINK
Haha good job. I'm not sure how you set up the whole system of keeping track who has voted, so unless you can write the code yourself, explain a little :)
tottenham_ru...
Member
11 Points
87 Posts
Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.A...
Jun 02, 2010 08:48 PM|LINK
Sadly I have no idea
rsw20
Member
548 Points
112 Posts
Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.A...
Jun 02, 2010 08:55 PM|LINK
Copy this codeand run
function hasvalues() as boolean Dim currentUser As MembershipUser = Membership.GetUser() Dim currentUserId As Guid = CType(currentUser.ProviderUserKey, Guid) Dim retvalue As Boolean = false Dim connectionString As String = ConfigurationManager.ConnectionStrings("SecurityTutorialsConnectionString").ConnectionString Dim insertSql As String = "SELECT COUNT(*) FROM Awards WHERE UserId = @UserId" Using myConnection As New SqlConnection(connectionString) Dim myCommand As New SqlCommand(insertSql, myConnection) myCommand.Parameters.AddWithValue("@UserId", currentUserId) Try myConnection.Open() Dim val = mycommand.executescalar() if val isnot nothing then if int32.parse(val) > 0 then retvalue = true end if end if myConnection.Close() Catch ex As Exception throw ex End Try End Using return retvalue end functionhoodedperson...
Star
12950 Points
3196 Posts
Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.A...
Jun 02, 2010 09:00 PM|LINK
Oh wow, I forgot you already showed the query to insert stuff...that way we can just take stuff out of the database! This will be put in your hasvoted() function:
Dim currentUser As MembershipUser = Membership.GetUser() Dim currentUserId As Guid = CType(currentUser.ProviderUserKey, Guid) Dim connectionString As String = ConfigurationManager.ConnectionStrings("SecurityTutorialsConnectionString").ConnectionString Dim insertSql As String = "SELECT * FROM Awards WHERE UserID='" & currentUserId & "'" Using myConnection As New SqlConnection(connectionString) Dim myCommand As New SqlCommand(insertSql, myConnection) Dim reader As New SqlReader = myCommand.ExecuteReader() If(Not reader.HasRows()) Return False Else Return True End IfIt should work. Let me know!