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
Dim userID As String = Session("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()
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()
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?