0

在将它们转换为二进制数据后,我已将一些 DataGridViewImage 列保存到 sql 中。我需要将它们写回我的 datagridview 控件。这是代码的一部分。当我运行此代码时,我收到错误“无效参数”任何想法?谢谢

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim cmdselect As SqlCommand = New SqlCommand("SELECT * FROM tblImgData", _Connection)
    _Connection.Open()
    Try
        Using dataAdapter As New SqlDataAdapter(cmdselect)
            Using commandBuilder As New SqlCommandBuilder(dataAdapter)
                Dim dataTable As New DataTable()
                dataTable.Locale = System.Globalization.CultureInfo.InvariantCulture
                dataAdapter.Fill(dataTable)
                For x = 0 To (dataTable.DefaultView.Count - 1)
                    Dim barrImg As Byte() = DirectCast(dataTable.Rows(x).Item(1), Byte())
                    dataTable.Rows(x).Item(1) = Image.FromStream(New MemoryStream(barrImg))
                Next
                Dim bindingSource1 As New BindingSource()
                bindingSource1.DataSource = dataTable
                DataGridView1.DataSource = bindingSource1
            End Using
        End Using
    Catch ex As Exception
        MessageBox.Show("Error: " + ex.Message, "Connection error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
        ' finish the program   
        Application.[Exit]()
    End Try
End Sub
4

0 回答 0