hi
i use this code to uploading image
<asp:UpdatePanel ID="Upbdt1" runat="server">
<ContentTemplate>
<asp:ModalPopupExtender DropShadow="true" ID="ModalPopupExtender1"
PopupControlID="PnPopup1" runat="server" TargetControlID="BtnPopup1"
>
</asp:ModalPopupExtender>
<asp:Button ID="BtnPopup1" OnClick="BtnPopup_Click" runat="server" Text="select image" CssClass="DPC9_Img1" BorderStyle="Solid" BorderWidth="0px" BorderColor="White" />
<asp:Panel ID="PnPopup1" runat="server" BackColor="White"
CssClass="panel">
<asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="~/image/close.png" />
<br />
<asp:FileUpload ID="fup1" runat="server"
ToolTip="click" />
<asp:Button ID="BtnUpload1" OnClick="BtnUpload_Click" runat="server" Text="load" />
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="BtnUpload1" />
</Triggers>
</asp:UpdatePanel>
and
protected void BtnUpload1_Click(object sender, EventArgs e)
{
string path = Server.MapPath(".") + "\\../image/House\\";
string[] validext = { ".jpg", ".gif", ".png", ".rar" };
string ext =
System.IO.Path.GetExtension(AsyncFileUpload1.PostedFile.FileName);
if (Array.IndexOf(validext, ext.ToLower()) < 0)
{
lblMessage.Text = "please enter correct format";
return;
}
string filename = System.IO.Path.GetFileName(fup1.PostedFile.FileName);
while (System.IO.File.Exists(path + "\\" + filename))
filename = "1" + filename;
if (fup1.HasFile)
{
try
{
if (fup1.PostedFile.ContentLength < 105000)
{
fup1.PostedFile.SaveAs(Server.MapPath("~/Upload") + System.IO.Path.DirectorySeparatorChar + AsyncFileUpload1.PostedFile.FileName);
Label20.Text = "File " + fup1.PostedFile.FileName + " uploaded successfully.";
}
else
{
Label20.Text = "File size of " + Convert.ToString(fup1.PostedFile.ContentLength / 1024) + " KB is exceeding the uploading limit.";
}
}
catch (Exception ex)
{
// error message
Label20.Text = "Some problem occurred while uploading the file. Please try after some time.";
}
}
else
{
// warning message
Label20.Text = "Please choose a file to upload.";
}
fup1.PostedFile.SaveAs(path + filename);
SqlCommand _cmd = new SqlCommand("Fileup4", _cn);
_cmd.CommandType = CommandType.StoredProcedure;
string data = Server.UrlDecode(Request.QueryString["BehCode3"]);
_cn.Open();
_cmd.Parameters.AddWithValue("@image2", fup1.FileBytes);
_cmd.Parameters.AddWithValue("@Behcode", data);
_cmd.ExecuteNonQuery();
_cn.Close();
}
Store Procedure
create procedure dbo.Fileup4
@image2 varbinary(MAX),
@behcode varchar(10)
@id int
as
begin
update image set image2=@image2
where behcode=@behcode and id=@id
end
i want it update table according to behtop and id column for @behtop i use these code
string data = Server.UrlDecode(Request.QueryString["BehCode3"]);
_cmd.Parameters.AddWithValue("@Behcode", data);
but i don't know what should i write fo @ID?
Best regards