将longblob图像保存到数据库

时间:2015-09-28 16:13:40

标签: vb.net image datagridview

我想从datagridview获取图像,然后将其保存到数据库中。谁能帮我这个?非常感谢

以下是我在数据库中保存图像的代码。我不知道为什么,但它实际上并没有保存任何东西。

Try
    connectionSync()
    Dim a, b As String
    Dim Sql = "INSERT INTO SAMPLE (ID, IMG)values(@a,@b)"

    For i As Integer = 0 To Me.DataGridView1.Rows.Count - 1
        a = Me.DataGridView1.Rows(i).Cells(0).Value.ToString()
        Dim cmd As New MySqlCommand(Sql, ConSync)


        Dim memorystream1 As New MemoryStream()
        Dim filename As String = DataGridView1.Rows(i).Cells(1).Value
        Dim bitmaps As New Bitmap(filename)
        bitmaps.Save(memorystream1, Imaging.ImageFormat.Jpeg)
        Dim pic() As Byte = memorystream1.GetBuffer()

        cmd.Parameters.AddWithValue("@a", a)
        cmd.Parameters.AddWithValue("@b", bitmaps)
        cmd.ExecuteNonQuery()
        cmd.Parameters.Clear()
    Next
    ConSync.Close()
Catch ex As Exception
       MsgBox(ex.Message)
End Try

0 个答案:

没有答案