Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 14973

Image retrieve from SQL DB

$
0
0
Hi,

I am trying to retrieve image and display it on the picturebox2 on datagridview cellmouseclick but receive the following error message:

Code:

System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index'

Code:

This exception was originally thrown at this call stack:
    [External Code]
    RCMS.FrmRegisterTenant.DgTenantDetails_CellMouseClick(Object, System.Windows.Forms.DataGridViewCellMouseEventArgs) in FrmRegisterTenant.vb
    [External Code]

The code I am using is:

Code:

Private Sub DgTenantDetails_CellMouseClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DgTenantDetails.CellMouseClick

        Dim conn As SqlConnection = GetDbConnection()

        Call TenantsDetailsDisable()

        If e.RowIndex >= 0 Then
            Dim row As DataGridViewRow = DgTenantDetails.Rows(e.RowIndex)

            TxtFNameUp.Text = row.Cells(1).Value.ToString
            TxtLNameUp.Text = row.Cells(2).Value.ToString
            TxtTelUp.Text = row.Cells(3).Value.ToString
            TxtEmailUp.Text = row.Cells(4).Value.ToString
            TxtNationalIDUp.Text = row.Cells(5).Value.ToString


            Dim img As Byte
            img = DgTenantDetails.Item(7, e.RowIndex).Value
            Dim ms As New MemoryStream(img)
            PictureBox2.Image = Image.FromStream(ms)
            PictureBox2.SizeMode = PictureBoxSizeMode.StretchImage

        End If
    End Sub

Secondly, issue (2) when I click on the datagridview I also receive the following error message:

Code:

The following exception occurred in the DataGridView.

System.Data.NoNullAllowedException: Column 'firstname' does not allow null

Note: firstname is not NULL - I dont understand.

Thanks

Viewing all articles
Browse latest Browse all 14973

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>