Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table's column "Pictures" and I set its DataType as IMAGE.
But error occurs "No mapping exist from object type System.Windows.Forms.PictureBox to a known managed provider native type". How do I fix this problem? Thanks

What I have tried:

VB
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        Dim cmd As New SqlCommand
        Try
            conn.ConnectionString = strcon
            conn.Open()
            cmd.Connection = conn
            cmd.CommandText = "INSERT INTO PatientInfo (Surname,Firstname,MI,Gender,Birthday,Address,Contact,Email, Picture) VALUES(@Surname,@Firstname,@MI,@Gender,@Birthday,@Address,@Contact,@Email,@Photo)"

            cmd.Parameters.AddWithValue("@Surname", txtSurname.Text)
            cmd.Parameters.AddWithValue("@Firstname", txtFirstname.Text)
            cmd.Parameters.AddWithValue("@MI", txtMI.Text)
            cmd.Parameters.AddWithValue("@Gender", CmbxGender.Text)
            cmd.Parameters.AddWithValue("@Birthday", dtpBday.Text)
            cmd.Parameters.AddWithValue("@Address", txtAdd.Text)
            cmd.Parameters.AddWithValue("@Contact", txtContact.Text)
            cmd.Parameters.AddWithValue("@Email", txtEmail.Text)
            cmd.Parameters.AddWithValue("@Photo", picbx2x2)
            cmd.ExecuteNonQuery()
            MessageBox.Show("Successful Added Data")
            loadData()
            conn.Dispose()
            conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try



    End Sub
Posted
Updated 24-Jan-17 1:42am
Comments
[no name] 17-Jan-17 18:06pm    
IF it were correct it would be picbx2x2.Image which is why you get the error. BUT it's not correct. You need to convert the image to a stream of bytes and save that to your database.
Member 12905345 17-Jan-17 21:10pm    
How could I do that sir?

1 solution

As indicated above pictures are stored in a SQL server as a blob.

Its a bit more involved than saving normal field information.

See the following link as an example for search google for saving blob into sql. There are plenty of examples on the internet

<a href">http://www.akadia.com/services/dotnet_read_write_blob.html[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900