Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello programmers got a few problem here.. As you see I want to save picture on my database but I cannot cause using breakpoints it show that my fileupload doesnt have an image,but when I check it I already choose picture. So it just loop on my if statement? Is an Updatepanel an issue here?
My code
client side
<asp:Panel ID="PanelSelling" Visible ="false" runat="server" Height="850px" Width="700px" >
               <br />
   <br />
   <br />
        
   <asp:Label ID="Label13" runat="server" Text="Browse Picture:" Width="212px"></asp:Label>
   <asp:FileUpload ID="imgUpload" runat="server" /><br />
   <br />
         <asp:Label ID="Label14" runat="server" Text="Add Title:"
       Width="180px"></asp:Label>
   <asp:TextBox ID="txtTitle" runat="server"  Font-Names="verdana"
                       Font-Size="X-Small" Width="300px"></asp:TextBox><br />
       <br />
         <asp:Label ID="Label15" runat="server" Text="Description:"
       Width="180px"></asp:Label><br />
   <br />
                                                                                    
   <asp:TextBox ID="txtDescription" runat="server" Height="49px" TextMode="MultiLine"  Font-Names="verdana"
                       Font-Size="X-Small" Width="300px"></asp:TextBox><br />
   <br />
        
   <asp:Label ID="Label16" runat="server" Text="Price" Width="180px"></asp:Label>
   <asp:TextBox ID="txtPrice" runat="server" Font-Names="verdana"
                       Font-Size="X-Small" Width="300px"></asp:TextBox><br />
   <br />
        
   <asp:Label ID="Label17" runat="server" Text="Quantity" Width="180px"></asp:Label>
   <asp:TextBox ID="txtQuantity" runat="server" Font-Names="verdana"
                       Font-Size="X-Small" Width="300px"></asp:TextBox><br />
   <br />
          
   <asp:Label ID="Label18" runat="server" Text="Category" Width="180px"></asp:Label>
   <asp:DropDownList ID="drpdwnCategory" runat="server" CssClass="p1"
                       Font-Names="Verdana" Font-Size="XX-Small" Height="16px" Width="303px">
                   </asp:DropDownList>
   <br />
   <br />
   <br />
   <br />
   <br />
   <br />
   <br />
   <br />
                           
   <asp:Button ID="btnSelltheProduct" runat="server" Text="Sell Product" Width="200px" CssClass="button2" />
       
   <br />
          
   <br />
   <br />
               </asp:Panel>

it is inside a update panel
and on my server side here is my code
VB
Dim userID As String = Session("UserID")
        'get data from userID
        _userDAL = New UserDAL
        Dim user As New User
        user = _userDAL.SelectByUserID(userID)
        If user IsNot Nothing Then
            Dim account As String = user.AccountNo
            Dim stringmode As String = 1
            Dim cn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ECommerceConnectionString").ConnectionString)
            cn.Open()
            'If imgUpload.PostedFile IsNot Nothing AndAlso imgUpload.PostedFile.FileName <> "" Then
            '    Dim imageSize As Byte() = New Byte(imgUpload.PostedFile.ContentLength - 1) {}
            '    Dim uploadedImage__1 As HttpPostedFile = imgUpload.PostedFile
            '    uploadedImage__1.InputStream.Read(imageSize, 0, CInt(imgUpload.PostedFile.ContentLength))


            'End If
            Try
                Dim img As FileUpload = DirectCast(FindControl("imgUpload"), FileUpload)
                Dim imgByte As [Byte]() = Nothing
                If img.HasFile AndAlso img.PostedFile IsNot Nothing Then
                    Dim File As HttpPostedFile = imgUpload.PostedFile
                    imgByte = New [Byte](File.ContentLength - 1) {}
                    File.InputStream.Read(imgByte, 0, File.ContentLength)
                End If
                Dim sql As String = "INSERT INTO [Selling](Image,Title,Description,UserID,Quantity,AccountNo,Price,CategoryID,Mode) VALUES(@Image,@Title,@Description,@UserID,@Quantity,@AccountNo,@Price,@CategoryID,@Mode)"
                Dim cmd As SqlCommand = New SqlCommand(sql, cn)
                cmd.Parameters.AddWithValue("@Image", imgByte)
                cmd.Parameters.Add("@Title", SqlDbType.NVarChar, 120).Value = txtTitle.Text
                cmd.Parameters.Add("@Description", SqlDbType.NVarChar, 500).Value = txtDescription.Text
                cmd.Parameters.Add("@UserID", SqlDbType.NVarChar, 12).Value = userID
                cmd.Parameters.Add("@Quantity", SqlDbType.NVarChar, 12).Value = txtQuantity.Text
                cmd.Parameters.Add("@AccountNo", SqlDbType.NVarChar, 12).Value = account
                cmd.Parameters.Add("@Price", SqlDbType.NVarChar, 12).Value = txtPrice.Text
                cmd.Parameters.Add("@CategoryID", SqlDbType.NVarChar, 12).Value = drpdwnCategory.SelectedValue
                cmd.Parameters.Add("@Mode", SqlDbType.NVarChar, 12).Value = stringmode
                cmd.ExecuteNonQuery()
                SetFocus(MsgBox("Saved"))
                InitiateClear()

                'SetFocus(MsgBox("Error Occured while saving"))
            Finally
                cn.Close()
            End Try
        End If


Basically I am switching on the comment but still it doesnt work. Any Ideas ? Sorry for my english

My question is sir I cant save picture to my data base using that code.. Is there any problem regarding my codes?
Posted
Updated 17-Jan-12 15:52pm
v2
Comments
Sergey Alexandrovich Kryukov 17-Jan-12 15:21pm    
Not clear. Don't smash all together, explain one fact at a time.
--SA

1 solution

The UpdatePanel is not compatible with FileUpload controls. There are some work-arounds or alternatives such as these

http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/AsyncFileUpload/AsyncFileUpload.aspx[^]

Simple AJAX File Upload[^]
 
Share this answer
 
Comments
janwel 19-Jan-12 20:29pm    
thanks sir

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