Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. how to save images in sqlserver again retrive from sqlserver using asp.net control

how to save images in sqlserver again retrive from sqlserver using asp.net control

Scheduled Pinned Locked Moved Web Development
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Ch Gayatri Subudhi
    wrote on last edited by
    #1

    Hi I am trying to store the images using asp.net browser control ie, fileupload. .Its with store the images in to the databse where i used as sqlserver as backend. It store but, after that i am trying to retrive those images through listview from backend. But here i am getting no error but no images are there in images.I need the names of the images in the listview from backend while clicking a particular image it should be enlarge in image control.Thanks in advance.Please help me. In default.aspx.cs page: public partial class _Default : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DigitalSignageConnectionString2"].ConnectionString.ToString()); protected void Page_Load(object sender, EventArgs e) { } protected void BthSnd_Click(object sender, EventArgs e) { con.open(); SqlCommand mycommand = new SqlCommand("INSERT INTO Image_DiSig([image], [text],[path],[image1]) VALUES (@image, @text,@imgpath) ", con); string apppath = Request.PhysicalApplicationPath; FileUpload1.SaveAs(apppath + "images\\" + FileUpload1.FileName); string imgpath = apppath + "images\\" + FileUpload1.FileName; FileStream fs = File.OpenRead(imgpath); byte[] imagedata = new byte[fs.Length]; mycommand.Parameters.AddWithValue("@image", imagedata); mycommand.Parameters.AddWithValue("@text", TextBox1.Text); mycommand.Parameters.AddWithValue("@imgpath", apppath); mycommand.ExecuteNonQuery(); con.Close(); } public string FormatURL2(object strArgument) //used to get that image bytes(while tracing its picking that bytes but not converting into image) { return ("Default2.aspx?id=" + strArgument); } protected void LinkButton1_Click(object sender, EventArgs e) { SqlDataAdapter da = new SqlDataAdapter("select * from Image_DiSig",con); DataSet ds = new DataSet(); da.Fill(ds); ListView1.DataSource = ds; ListView1.DataBind(); } protected void ListView1_SelectedIndexChanged(object sender, EventArgs e) { Image1.ImageUrl = ListView1.SelectedValue.ToString(); } in default.aspx source page: <asp:ListView ID="ListView1" runat="server" onselectedindexchanged="ListView1_SelectedIndexChanged" SelectedIndex="0" > <LayoutTemplate> <div style="border:dotted 1px black;"> <asp:PlaceHolder ID="itemPlaceholder" runat="server" /> </div> </LayoutTemplate> <ItemTemplate> <img alt="name" align="middle" height="50px" width="100px" name="Image1" src='<%# FormatURL2(DataBinder.Eval(Container.DataItem, "id")) %>' />

    M 1 Reply Last reply
    0
    • C Ch Gayatri Subudhi

      Hi I am trying to store the images using asp.net browser control ie, fileupload. .Its with store the images in to the databse where i used as sqlserver as backend. It store but, after that i am trying to retrive those images through listview from backend. But here i am getting no error but no images are there in images.I need the names of the images in the listview from backend while clicking a particular image it should be enlarge in image control.Thanks in advance.Please help me. In default.aspx.cs page: public partial class _Default : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DigitalSignageConnectionString2"].ConnectionString.ToString()); protected void Page_Load(object sender, EventArgs e) { } protected void BthSnd_Click(object sender, EventArgs e) { con.open(); SqlCommand mycommand = new SqlCommand("INSERT INTO Image_DiSig([image], [text],[path],[image1]) VALUES (@image, @text,@imgpath) ", con); string apppath = Request.PhysicalApplicationPath; FileUpload1.SaveAs(apppath + "images\\" + FileUpload1.FileName); string imgpath = apppath + "images\\" + FileUpload1.FileName; FileStream fs = File.OpenRead(imgpath); byte[] imagedata = new byte[fs.Length]; mycommand.Parameters.AddWithValue("@image", imagedata); mycommand.Parameters.AddWithValue("@text", TextBox1.Text); mycommand.Parameters.AddWithValue("@imgpath", apppath); mycommand.ExecuteNonQuery(); con.Close(); } public string FormatURL2(object strArgument) //used to get that image bytes(while tracing its picking that bytes but not converting into image) { return ("Default2.aspx?id=" + strArgument); } protected void LinkButton1_Click(object sender, EventArgs e) { SqlDataAdapter da = new SqlDataAdapter("select * from Image_DiSig",con); DataSet ds = new DataSet(); da.Fill(ds); ListView1.DataSource = ds; ListView1.DataBind(); } protected void ListView1_SelectedIndexChanged(object sender, EventArgs e) { Image1.ImageUrl = ListView1.SelectedValue.ToString(); } in default.aspx source page: <asp:ListView ID="ListView1" runat="server" onselectedindexchanged="ListView1_SelectedIndexChanged" SelectedIndex="0" > <LayoutTemplate> <div style="border:dotted 1px black;"> <asp:PlaceHolder ID="itemPlaceholder" runat="server" /> </div> </LayoutTemplate> <ItemTemplate> <img alt="name" align="middle" height="50px" width="100px" name="Image1" src='<%# FormatURL2(DataBinder.Eval(Container.DataItem, "id")) %>' />

      M Offline
      M Offline
      Mohammad Dayyan
      wrote on last edited by
      #2

      Have you checked http://www.google.com/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&hs=n2Z&q=store+image+in+SQL+.NET&btnG=Search&lr=[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups