System.byte []到datagrid

时间:2013-06-19 00:47:00

标签: vb.net

我将一些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

0 个答案:

没有答案