如何将字符串转换为Image数据类型 [英] How to convert string to Image datatype

查看:164
本文介绍了如何将字符串转换为Image数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友

我有3个字段ID,ImageName,ImagePath
的数据库 ImageName和ImagePath的数据类型为Nvarchar

我创建了一个全局变量:-

hi friends

i have database in which 3 fields ID , ImageName, ImagePath
datatype for ImageName and ImagePath is Nvarchar

i have created a global variable :-

private Image _ProductImage;
 public Image ProductImage
    {
        get { return _ProductImage; }
        set { _ProductImage = value; }


    }

返回图像数据类型

我在aspx中有一个imagecontrol
在该图像控件中,我必须显示数据库中的图像,其中在数据库中仅在字符串中定义了路径

which returns image datatype

i have a imagecontrol in my aspx
in that image control i have to display image from database where in database only the path is defined in string

Products prod = new Products();
prod.ProductImage = sdr["ImagePath"];
ImageItem.ImageUrl = Server.MapPath(prod.ProductImage);


这段代码有些错误,请弄清楚朋友们....紧急


some wrong in this code please figure it out friends.... URGENT

推荐答案

嗨 您可以不使用Server.MapPath尝试吗?开始时使用〜".

ImageItem.ImageUrl =〜/IMAGES/Test.ico";


问候
Dominic
Hi Can you try without using Server.MapPath ? Using ''~'' in the beginning.

ImageItem.ImageUrl = "~/IMAGES/Test.ico";


Regards
Dominic


朋友我知道了.....我会和你分享...

我改变了
friend i got it..... i will share with you...

i changed
private Image _ProductImage; 
public Image ProductImage 
{ 
  get { return _ProductImage; } 
  set { _ProductImage = value; } 
}




to

private string_ProductImage; 
public string ProductImage 
{
 get { return _ProductImage; } 
 set { _ProductImage = value; } 
} 


并创建了一个


and created a

private void showimage(string imagepath) 
{
 imagecontrol.ImageUrl = "~/foldername/" + imagepath +""; 
}


并称为


and called this

prod.ProductImage = sdr["PImagePath"].ToString(); showimage(prod.productImage);



[edit]添加了代码块[/edit]



[edit]code block added[/edit]


这篇关于如何将字符串转换为Image数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆