当我尝试将多张图片上传到数据库时,我的代码工作正常并且所有图片都显示在图库中,但是当我尝试修改数据库中的图片并修改一张图片时,它会删除其余的图片。数据库。记录集没有被删除,其余的信息保持不变,它只有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 :(得分:0)
我找到了它正在查看所有文件上传控件的解决方案,因为它们中没有任何内容它会引用我刚才想到的那些字段,很忙,从来没有时间发布我的答案。在数据库中删除其中的任何内容并将其替换为空格。我将代码更改为用户选择要更新的插槽的位置,然后继续使用qstring而不是一次更新所有这些代码