【问题标题】:How to populate datagridview with data which has data and images stored in sqlserver table如何使用存储在 sql server 表中的数据和图像的数据填充 datagridview
【发布时间】:2015-10-13 05:26:31
【问题描述】:

我已经阅读了很多关于这个问题的文章。但是没有得到正确的答案,或者可能是我无法理解。

我有一个表格,将收据编号、批号和收据副本作为图像存储在数据库中

例如:Referenceid : int 批号:整数 收据压缩:图片

我正在尝试在 datagridview 中显示这些数据

 Dim sqlString As String
 Dim storeID As String
 Dim saleDate As String
 Dim ds As DataSet

 With DataGridView1
     storeID = .CurrentRow.Cells(1).Value
     saleDate = .CurrentRow.Cells(2).Value
 End With

 sqlString = "select batchnumber, [time],ReceiptCompressed from Journal where TransactionType=16 and StoreId ='" & storeID & "'" & _
                 "  and [Time] between '" & saleDate & " 00:00:00' and '" & saleDate & " 23:59:59'"




 ds = getDataset(connectionString, sqlString)

 DataGridView2.DataSource = ds.Tables(0)

问题是加载数据时出现错误。

"datagridview出现如下错误

system.argumentexception.image.fromstream(system system, boolean useembeddedcolormanagement, boolean validateimagedata" etc.....

谁能告诉我最简单的方法是什么?如前所述,存储在表中的数据我想与图像一起加载到 datagridview 中。

谢谢 文卡特

【问题讨论】:

  • 图片是these格式之一吗?

标签: vb.net datagridview populate


【解决方案1】:

尝试将图像保存为 base64 字符串:

Dim byt As Byte() = System.Text.Encoding.UTF8.GetBytes(strTextOrFile)
strModified = Convert.ToBase64String(byt)

...并将它们保存到您的数据库中。要将 base64 字符串转换为图像,请使用:

Dim b As Byte() = Convert.FromBase64String(strModified)
strTextOrFile = System.Text.Encoding.UTF8.GetString(b)

处理图像的另一种方法是不将它们保存到您的数据库中,而只保存他的路径。

【讨论】:

  • 我有一个将 pos 收据存储在数据库中的应用程序。比较 X 报告(日终)和报告的实际销售额是一项繁琐的活动。我要做的是创建一个应用程序,在选择日期和商店名称时显示数据库中的 X 报告并显示在图片框中。这为用户节省了大量时间。
  • 我不明白为什么会生成“参数无效”错误。 sql server 数据库中字段的数据类型是'image',和web中的例子一样。
  • 可能与您使用的基本语言(以及您的实际编码)有关。出现错误时,您能否发布一些正在使用的值?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-22
  • 2015-04-02
  • 2014-03-27
  • 1970-01-01
  • 2017-10-10
相关资源
最近更新 更多