【问题标题】:How do I add an image to an DataTable?如何将图像添加到 DataTable?
【发布时间】:2012-07-15 11:09:36
【问题描述】:

我想做的是将包含图像的列添加到 DataTable。创建列/行后,DataTable 将作为 DataGrid 的源。

我尝试了 resolveUrl 方法,但没有成功。

您能帮我在我的数据表中添加一个图像列吗?

【问题讨论】:

标签: c# image datagrid datatable


【解决方案1】:

取自This Question

 DataTable table = new DataTable("ImageTable"); //Create a new DataTable instance.

 DataColumn column = new DataColumn("MyImage"); //Create the column.
column.DataType = System.Type.GetType("System.Byte[]"); //Type byte[] to store image bytes.
 column.AllowDBNull = true;
 column.Caption = "My Image";

 table.Columns.Add(column); //Add the column to the table.

然后你可以这样设置MyImage列

DataRow row = table.NewRow();
row["MyImage"] = <Image byte array>;
tables.Rows.Add(row);

【讨论】:

  • 我怎样才能将我的图像加载到字节数组中?
  • 查看codeproject.com/Articles/15460/… 获取一些示例代码和教程
  • 我不太明白如何设置链接中教程中的图片链接。如果你能解释一下,我将非常感激。很抱歉不能给你投票,因为我没有 15 声望。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-13
  • 2012-10-25
  • 1970-01-01
  • 2021-08-31
  • 2021-11-16
  • 2011-08-07
相关资源
最近更新 更多