Click here to Skip to main content
16,012,223 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have small project which is something like news portal where one is allowed to post news.now database structure is something like this . news table has following columns

news : newsid int , news varcahr

and resource table
resource : resid int
nwsfref int -->it refereces to newsid
path varchar-->contains path of folder where images/videos are uploaded

for resource uploaded i am using fileupload control .

as we know one must explicitly provide a control or mechanism to allow the user to submit the specified file. i am using button that the user clicks to upload the image as well as news

but problem with this approach that for a single news only one img/videos can be uploaded . what do if i want to to upload multiple images for single news item. i mean to say that i wanted to uplaod multiple image plus news should be uploaded on single click of an button

please help .
thank u
anoop

update

here is mu stored procedure for inserting news and images in database but its giving me foregin key constriants
please correct the logic

stored procedure to insert news
create procedure spnews @title varchar(50),@news varchar(max)
   as begin
          declare @idint int
          select @idint = max(newsid) from newso
            if @idint is null
                  set @idint = 1
            else 
                  set @idint = @idint + 1
                  
            insert into newso values(@idint,@title,@news)
            
    end  


and here is stored procedure for inserting into resource table but its giving me error of foregin key constaint
create procedure spres @title varchar(50),@path varchar(max)
   as begin
     declare @intid int,@refid int,@fullpath varchar(max)
     
     select @intid = max(resid) from  resource
          if @intid is null
             set @intid = 1
          else
             set @intid = @intid + 1
     
     select @refid = max(newsid) from newso
          if @refid is null
             set @refid = 1
          else
             set @refid = @refid + 1
             
          if @path is not null
             set @fullpath = '~/uplaod/'+@path    
          else
             set @fullpath = null 
             
      insert into resource values(@intid,@refid,@title,@fullpath)  
   end


[Edited]Code is wrapped in "pre" tag[/Edited]
Posted
Updated 26-Nov-11 10:22am
v4

1 solution

Just have multiple resource table entries, with the same newsid:

News:
  id     news
10001    Explosion!
10002    Fire!
10003    Care crashes into UFO!


Resource:
  id     nwsfref   path
100001    10001     C:\Exp\0001.jpg
100002    10002     C:\Fir\0007.jpg
100003    10002     C:\Fir\0008.jpg
100004    10003     C:\CCU\0101.jpg
That gives you one pic each for Explosion and Crash, and two for Fire.
 
Share this answer
 
Comments
mhamad zarif 26-Nov-11 13:04pm    
my 5. This is the solution.
anoop_vip 26-Nov-11 13:34pm    
thanks mate i am going on same line but i wanted to uplaod multiple image plus news should be uploaded on single click of a button
RaviRanjanKr 26-Nov-11 16:24pm    
Nice Answer, My 5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900