2010-12-02 83 views
0

當我嘗試上傳多張圖片到數據庫時,我的代碼工作正常,所有圖片都顯示在圖庫中,但是當我嘗試修改數據庫中的圖片並修改其中一張圖片時從數據庫中刪除剩餘的圖片。記錄集沒有被刪除,其餘的信息保持不變,只有5多個地方的數據被刪除。這裏是我到目前爲止的代碼..上傳文件時從數據庫中刪除的記錄

message.Text = "please wait" 
    pics.Visible = False 
    'wherepics are stored 
    Dim savepath As String = Server.MapPath("/cgi-bin/properties/") 
    Dim tfn0 As String = "" 
    Dim tfn1 As String = "" 
    'dims the filenames a variables 
    Dim img0 As String = pic0.FileName 
    Dim img1 As String = pic1.FileName 
    'this is the set of paths to check 
    'this will check for redundencies in the database so no dublicate file names will occur 
    Dim ptc0 As String = savepath + img0 
    Dim ptc1 As String = savepath + img1 

    Dim url0 As String = "" 
    Dim url1 As String = "" 
    Dim counter As Integer = 2 
    If (System.IO.File.Exists(ptc0)) Then 
     While (System.IO.File.Exists(ptc0)) 
      tfn0 = counter.ToString = img0 
      ptc0 = savepath + tfn0 
      counter = counter + 1 
     End While 
    ElseIf (System.IO.File.Exists(ptc1)) Then 
     While (System.IO.File.Exists(ptc1)) 
      tfn1 = counter.ToString = img1 
      ptc1 = savepath + tfn1 
      counter = counter + 1 
     End While 
    End If 
    Dim sp0 As String = savepath + img0 
    Dim sp1 As String = savepath + img1 
    If Not pic0.FileName = Nothing Then 
     pic0.SaveAs(sp0) 
     img0 = pic0.FileName 
     url0 += "pic_main" 
     url1 += img0 
    End If 
    If Not pic1.FileName = Nothing Then 
     If pic0.FileName = Nothing Then 
      pic1.SaveAs(sp1) 
      img1 = pic0.FileName 
      url0 += "pic_one" 
      url1 += img1 
     Else 
      pic1.SaveAs(sp1) 
      img1 = pic0.FileName 
      url0 += ", pic_one" 
      url1 += ", " & img1 
     End If 

    End If 

    Dim datanames() As String = {url0} 
    ', "pic_six", "pic_seven", "pic_eight", "pic_nine" 
    Dim datavalues() As String = {url1} 
    ', file6, file7, file8, file9 
    DB.UpdateCommand(datanames, datavalues, "property", "property_id = " & Request.QueryString("id")) ', true) 
    Response.Redirect("finished.aspx") 
+0

我發現它正在查看所有文件上傳控件,因爲它們中沒有任何內容,它會引用我前一段時間想到的那些字段,忙於從未發佈時間發佈我的答案。在數據庫中並刪除其中的任何內容並將其替換爲空格。我稍微改變了代碼到用戶選擇他們想要更新的插槽的位置,然後傳遞一個qstring而不是一次更新所有的代碼。 – 2011-03-23 20:28:44

回答

0

我發現有人在看所有的文件上傳控件的解決方案,因爲沒有什麼是他們會引用這些領域我已經在不久前這個想通了,很忙,從來沒有時間發佈我的答案。在數據庫中並刪除其中的任何內容並將其替換爲空格。我將代碼稍微更改了一些,以便用戶選擇要更新的插槽,然後攜帶qstring而不是一次更新所有這些代碼