views:

96

answers:

1

I am developing a student registration form in asp.net. there are two tables viz std_registration and gallery(having pic_id and pic_url). During registration, before the click of submit button i want to retrieve pic_id from gallery table and then pass it to the insert query of registration table. image upload is an optional part. if no image is uploaded i want a default image to get uploaded.

pls help me on this. thanx.

+1  A: 

Your algorithm:

  1. Add new user, get Id of user.
    • The user is NOT optional and must be created. If not possible, the whole thing stops
  2. Look for the upload image, if not found return.
  3. Save the image, associating it to the user id.

Your tables should look like:

User

Id whatever PK
Name nvarchar(up to you)
YaddaYadda

ProfileImage

Id whatever PK
UserId whatever FK
Image Blob

The foreign key should NOT be in the User table. You aren't sharing images between users.

Will
is there a alternative way to do it?? i dont want to store the userid in the image table. just retrieve the image id and store it in the user table.
Vikrant
@vikrant - Why do you "want" that? Because its best? The fact is that you'll always have the current user ID handy, so your query to get the image is a one stop affair--"select blob from images where userid = @userId". Yes, you can always do it the other way. IMHO this is the best way to do it and will be easier to use and maintain over time. For instance, what happens when you need to associate more than one image per user? Your scheme makes that impossible. Mine requries no rework.
Will
ok thanks alot.. will do it ur way..
Vikrant