Profile Images

M

mihir.kotwal

I am trying to make a profile page that displays a user's profile
picture if they have added one. If they haven't added a picture, I want
a hyperlink to link to a page to upload it to the server. I have gotten
an upload page working where it stores the server file path on the
server and the corresponding user in an SQL database and then uploads
the picture. I want the hyperlink to link to a page that deletes the
picture if they have one attached to their profile.

Code of the edit profile page:
Partial Class noanon_editprofile
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim conn, rs, sql, pUser

'Visual Studio 2005 Express Edition made me declare the field
or else it would not build

conn = Server.CreateObject("ADODB.Connection")

'I have a conn.Open statement here and I named the field in the
database pUser because ASP was interpreting the field if it was User,
not SQL. I also have aspcompat=True, btw

sql = "SELECT pUser,FileLocation FROM profilepiclocations WHERE
pUser = 'User.Identity.Name'"
rs = conn.execute(sql)
If rs.Fields.Item(pUser) = User.Identity.Name Then
HyperLink3.Text = "Delete profile picture."
HyperLink3.NavigateUrl = "~/noanon/deletepicture.aspx"
Else
HyperLink3.Text = "Add profile picture."
HyperLink3.NavigateUrl = "~/noanon/uploadpicture.aspx"
End If
conn.Close()
End Sub
End Class

I haven't tried scripting the image tag yet. I have played around with
this code and either it didn't work or it gave me errors, like "Item
cannot be found in the collection corresponding to the requested name
or ordinal." What did I do wrong? Is there a better way do do this
through ASP.NET instead of ADO?
-Mihir
 
J

Jacek Stawicki

Uzytkownik <[email protected]> napisal w wiadomosci

Firs you declare pUser variable
Dim conn, rs, sql, pUser.

Than, you do not pass anywhere any value to this variable.
sql = "SELECT pUser,FileLocation FROM profilepiclocations WHERE
pUser = 'User.Identity.Name'"
rs = conn.execute(sql)
If rs.Fields.Item(pUser) = User.Identity.Name Then

Here you try to pass pUser variable as a parameter to Item property.
I suppose that you have omited quotation-marks or you have forgotten
to pass value (actually with column name) to pUser variable


ps.
Try to use SqlCommand instead of old-fashioned ADO commands.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top