我正在尝试使用 jQuery 和 Web 服务将 SQL 表中的 varbinary
图像显示为 html 表数据。请帮助我如何转换 int 以及如何显示它。
我的代码是这样的:
网络服务:
[WebMethod]
public a[] Bindpics()
{
DataTable dt = ga.retrievedata("select Picture from T_Sam");
List<a> details = new List<a>();
foreach (DataRow dtrow in dt.Rows)
{
a m = new a();
m.Pic = (byte[])dtrow["Picture"];
details.Add(m);
}
return details.ToArray();
}
public class a
{
public byte[] Pic { get; set; }
}
jQuery:
success: function (data) {
for (var i = 0; i < data.d.length; i++) {
$("#tbDetails").append("<tr><td>"
+ "<img src=" + "'" + data.d[i].Pic + "'" + " />" + "</td></tr>");
}
我遇到了一个错误
Unable to cast object of type \u0027System.DBNull\u0027 to type \u0027System.Byte[]\u0027
它没有显示图像。
请帮我转换一下。
最佳答案
我从网络服务转换图像然后问题就解决了......
关于c# - 如何在 ASP.NET MVC 中使用 jQuery 将 varbinary 图像显示到 html 表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41312705/