如何使用datagridview中的单元格内容单击事件将图像检索回到图片框?

时间:2018-09-08 16:24:40

标签: mysql-workbench vb.net-2010

我有用于插入数据的这段代码

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
    dbDataSet.Clear()

    load_table()



End Sub

我知道如何检索一些数据回到我的文本框。问题是我不知道如何仅通过单击Datagridview的单元格内容将图像检索回我的PictureBox。 这是我的代码,用于将一些数据检索回我的文本框

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

感谢您能提供的任何帮助。

0 个答案:

没有答案