单击datagrid视图的单元格内容时如何将图像检索到图片框

时间:2018-09-06 13:16:15

标签: vb.net mysql-workbench

我在MySQL中以LONGBLOB的数据类型保存了图像 这是我要保存的代码

Private Sub btnsave_Click(sender As System.Object, e As System.EventArgs) Handles btnsave.Click
    Dim mstream As New System.IO.MemoryStream()
    testpb.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
    Dim arrImage() As Byte = mstream.GetBuffer()

    MysqlConn = New MySqlConnection
    MysqlConn.ConnectionString =
        "server=localhost;userid=root;password=rico;database=god;"
    Dim READER As MySqlDataReader

    Try
        MysqlConn.Open()
        COMMAND.Connection = MysqlConn
        COMMAND.CommandType = CommandType.Text
        COMMAND.CommandText = "insert into god.precord (ID,LastName,FirstName,MiddleName,Address,ContactNo,Gender,Birthdate,Age,picture) values ('" & txtid.Text & "','" & txtlastname.Text & "','" & txtfirstname.Text & "','" & txtmiddlename.Text & "','" & txtaddress.Text & "','" & txtcontactno.Text & "','" & txtgender.Text & "','" & dtpbirthdate.Text & "','" & txtage.Text & "',@picture)"
        COMMAND.Parameters.AddWithValue("@picture", arrImage )
        READER = COMMAND.ExecuteReader


        MessageBox.Show("Data Saved")


        MysqlConn.Close()

    Catch ex As MySqlException
        MessageBox.Show(ex.Message)
    Finally
        MysqlConn.Dispose()

    End Try

然后我有这段代码用于检索数据

Private Sub DataGridView1_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    If e.RowIndex >= 0 Then
        Dim row As DataGridViewRow
        row = Me.DataGridView1.Rows(e.RowIndex)
        txtid.Text = row.Cells("ID").Value.ToString
        txtlastname.Text = row.Cells("LastName").Value.ToString
        txtfirstname.Text = row.Cells("FirstName").Value.ToString
        txtmiddlename.Text = row.Cells("MiddleName").Value.ToString
        txtaddress.Text = row.Cells("Address").Value.ToString
        txtcontactno.Text = row.Cells("ContactNo").Value.ToString
        txtgender.Text = row.Cells("Gender").Value.ToString
        dtpbirthdate.Text = row.Cells("Birthdate").Value.ToString
        txtage.Text = row.Cells("Age").Value.ToString


    End If

End Sub

如果我单击了datagridview中的单元格,如何检索图像。 我希望我的图片框等于我要检索的图像。 请帮我这是为了我想毕业的论文 提前谢谢:)

0 个答案:

没有答案