1

私の英語でごめんなさい

行に値があるかどうかを確認する方法を知りたいですか?

前もって感謝します :)

Private Sub uploadpic()

    Dim SQLCmd As New MySqlCommand("SELECT Picture FROM Student_information WHERE S_I_D = ('" & ListView1.Items(ListView1.FocusedItem.Index).SubItems(0).Text & "') ", dbcon)

    dbcon.Open()

    *Dim pictureData As Byte() = DirectCast(SQLCmd.ExecuteScalar(), Byte())*

    dbcon.Close()

    Dim picture As Image = Nothing

    'Create a stream in memory containing the bytes that comprise the image.

    Using stream As New IO.MemoryStream(pictureData)
        'Read the stream and create an Image object from the data.
        PictureBox4.Image = Image.FromStream(stream)
    End Using


End Sub
4

2 に答える 2

1

SQLCmd.ExecuteScalar()結果セットが空の場合、null 参照を返します。したがって、その値をチェックして、行に値があるかどうかを知ることができます。

于 2013-03-04T23:56:40.883 に答える
0

これを試して

Dim sql As string("SELECT Picture FROM Student_information WHERE S_I_D = ('{0}')",ListView1.Items(ListView1.FocusedItem.Index).SubItems(0).Text)
    tbl = GetRecords(sql)
        If tbl.Rows.Count > 0 Then
            'Code to execute
        Else
        exit sub 'or msgbox "record not found"
        End If 

Public Function GetRecords(ByVal sql As String) As DataTable
    Return GetRecordsExtracted(sql)
End Function

Private Function GetRecordsExtracted(ByVal sql As String) As DataTable
    Dim da As New SqlClient.SqlDataAdapter
    tbl = New DataTable
    da = New SqlClient.SqlDataAdapter(sql, dbcon.Open)
    da.Fill(tbl)
    Return tbl
End Function
于 2013-03-05T05:39:50.603 に答える