本文介绍了使用来自DB的图像地址在C#中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SearchImg.ImageUrl =〜/ images /;
我尝试过:
SearchImg.ImageUrl = "~/images/";
What I have tried:
string find = "select Image from tblImages where(Description like '%' + @des + '%')";
SqlCommand comm = new SqlCommand(find, conn);
comm.Parameters.Add("@des", SqlDbType.NVarChar).Value = imgsearch.Text;
conn.Open();
comm.ExecuteNonQuery();
SearchImg.ImageUrl = "~/images/";
conn.Close();
推荐答案
...
conn.Open();
comm.ExecuteNonQuery();
SqlDataReader reader = comm.ExecuteReader();
if (reader.Read()) {
SearchImg.ImageUrl = "~/images/" + reader["Image"].ToString();
}
conn.Close();
...
请注意,不使用anymoer时应丢弃对象。最简单的方法是使用使用
块。如果出现问题,您还应该进行适当的错误处理。例如,请查看 []
Note that you should dispose the objects when not used anymoer. Easiest way is to use a using
block. Also you should have proper error handling in case something goes wrong. For examples, have a look at Properly executing database operations[^]
这篇关于使用来自DB的图像地址在C#中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!