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. ASP.NET
  4. How to Display Image in Gridview from Sqlserver 2005 in C#

How to Display Image in Gridview from Sqlserver 2005 in C#

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasetutorial
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.
  • M Offline
    M Offline
    mrgaddam
    wrote on last edited by
    #1

    Hi, This is from chandrakanth. Actullay i am able to upload the picture into Sqlserver2005. But i can not able to get the picture. And i want to show the picture in Gridview. can any one tell me what are all things have to change in my code. here the code is protected void btnRetrive_Click(object sender, EventArgs e) { IDataReader objReader; SqlDataAdapter da = new SqlDataAdapter(); DataTable dt = new DataTable(); objReader= KF.Search.GetUserIdImages(txtuid.Text); dt.Load(objReader); gdvImagesRetrive.DataSource = dt; gdvImagesRetrive.DataBind(); } GetUserIdImages ------ that metyhod code is.... public static IDataReader GetUserIdImages(string strImageUserId) { try { byte[] imagestr; Database objDataBase = DatabaseFactory.CreateDatabase(); DbCommand objDbCommand = objDataBase.GetStoredProcCommand("STP_KF_Images_Retrive"); objDataBase.AddInParameter(objDbCommand, "@UserId", DbType.String, strImageUserId); IDataReader objDataReader; objDataReader = objDataBase.ExecuteReader(objDbCommand); while (objDataReader.Read()) { imagestr = (byte[])objDataReader.GetValue(1); } return objDataReader; objDataReader.Close(); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } } can any one tell me what are all things sholud change. Thanks and Regards Chandrakanth

    Chandrakanth

    B 1 Reply Last reply
    0
    • M mrgaddam

      Hi, This is from chandrakanth. Actullay i am able to upload the picture into Sqlserver2005. But i can not able to get the picture. And i want to show the picture in Gridview. can any one tell me what are all things have to change in my code. here the code is protected void btnRetrive_Click(object sender, EventArgs e) { IDataReader objReader; SqlDataAdapter da = new SqlDataAdapter(); DataTable dt = new DataTable(); objReader= KF.Search.GetUserIdImages(txtuid.Text); dt.Load(objReader); gdvImagesRetrive.DataSource = dt; gdvImagesRetrive.DataBind(); } GetUserIdImages ------ that metyhod code is.... public static IDataReader GetUserIdImages(string strImageUserId) { try { byte[] imagestr; Database objDataBase = DatabaseFactory.CreateDatabase(); DbCommand objDbCommand = objDataBase.GetStoredProcCommand("STP_KF_Images_Retrive"); objDataBase.AddInParameter(objDbCommand, "@UserId", DbType.String, strImageUserId); IDataReader objDataReader; objDataReader = objDataBase.ExecuteReader(objDbCommand); while (objDataReader.Read()) { imagestr = (byte[])objDataReader.GetValue(1); } return objDataReader; objDataReader.Close(); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } } can any one tell me what are all things sholud change. Thanks and Regards Chandrakanth

      Chandrakanth

      B Offline
      B Offline
      Bassam Saoud
      wrote on last edited by
      #2

      The way I do it is store the image path in the DB and then just retrieve the path an set it to the asp:image control in the Grid's ItemTemplate column. Hope this helps !

      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