質問

hi everyone i have created an ajax file-upload but it is importing only the first picture to my database can u help to resolve this issue please and the response.redirect is not working too

Dim sellerid1 As Integer
    Using con1 As New SqlConnection(_start)
        Dim conss1 As New SqlConnection(_start)
        Dim sql2 As String = "SELECT SellerID FROM Seller INNER JOIN Member ON Seller.MemberID = Member.MemberID WHERE(Member.Username = @username)"
        Dim mycommand As New SqlCommand(sql2, conss1)
        conss1.Open()
        mycommand.Parameters.AddWithValue("@username", Session("user"))
        sellerid1 = Convert.ToInt32(mycommand.ExecuteScalar)
    End Using

    Dim filename As String = e.FileName
    Dim strDestPath As String = Server.MapPath("~/Seller/images/")
    AjaxFileUpload1.SaveAs(strDestPath & filename)

    Dim Imagepath As String = "~/Seller/images/" & filename
    Dim conss As New SqlConnection(_start)
    conss.Open()
    Dim sql1 As String = "SELECT TOP (1) ItemID FROM Item WHERE  (SellerID = @sellerid) ORDER BY ItemID DESC"
    Dim mycommand2 As New SqlCommand(sql1, conss)
    mycommand2.Parameters.AddWithValue("@sellerid", sellerid1)
    ItemID = mycommand2.ExecuteScalar

    Dim sql As String = "INSERT INTO Image(Image,ItemID) VALUES (@image,@item)"
    Dim myCommand1 = New SqlCommand(sql, conss)

    myCommand1.Parameters.AddWithValue("@image", Imagepath)
    myCommand1.Parameters.AddWithValue("@item", ItemID)
    myCommand1.ExecuteNonQuery()
    Response.Redirect("Views/Default2.aspx")
役に立ちましたか?

解決

Try To Use UploadComplete and UploadCompleteEvent

Like Below:

 Protected Sub FileUpload_UploadComplete(sender As Object, e As AjaxControlToolkit.AjaxFileUploadEventArgs) Handles FileUpload.UploadComplete

    Using con1 As New SqlConnection(_start)
    Dim conss1 As New SqlConnection(_start)
    Dim sql2 As String = "SELECT SellerID FROM Seller INNER JOIN Member ON Seller.MemberID = Member.MemberID WHERE(Member.Username = @username)"
    Dim mycommand As New SqlCommand(sql2, conss1)
    conss1.Open()
    mycommand.Parameters.AddWithValue("@username", Session("user"))
    sellerid1 = Convert.ToInt32(mycommand.ExecuteScalar)
    End Using

    Dim filename As String = e.FileName
    Dim strDestPath As String = Server.MapPath("~/Seller/images/")
    AjaxFileUpload1.SaveAs(strDestPath & filename)

    Dim Imagepath As String = "~/Seller/images/" & filename
    Dim conss As New SqlConnection(_start)
    conss.Open()
    Dim sql1 As String = "SELECT TOP (1) ItemID FROM Item WHERE  (SellerID = @sellerid) ORDER BY ItemID DESC"
    Dim mycommand2 As New SqlCommand(sql1, conss)
    mycommand2.Parameters.AddWithValue("@sellerid", sellerid1)
    ItemID = mycommand2.ExecuteScalar

    Dim sql As String = "INSERT INTO Image(Image,ItemID) VALUES (@image,@item)"
    Dim myCommand1 = New SqlCommand(sql, conss)

    myCommand1.Parameters.AddWithValue("@image", Imagepath)
    myCommand1.Parameters.AddWithValue("@item", ItemID)
    myCommand1.ExecuteNonQuery()
 End Sub

 Protected Sub FileUpload_UploadCompleteAll(sender As Object, e As AjaxControlToolkit.AjaxFileUploadEventArgs) Handles FileUpload.UploadCompleteAll
    Response.Redirect("Views/Default2.aspx",False)
 End Sub
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top