How to Display Image in Gridview from Sqlserver 2005 in C#
-
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
-
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
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 !