如何将捕获的照片从相机保存到SQL服务器。

问题描述:

我有一个表的列图片,我将其DataType设置为IMAGE。

但是发生错误从对象类型System.Windows.Forms.PictureBox到已知的托管提供者本机没有映射类型。我该如何解决这个问题?谢谢



我尝试过:



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:

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

如上所示,图片作为blob存储在SQL服务器中。



比保存正常字段通知要多一些a / b


请参阅以下链接作为搜索google将blob保存到sql的示例。互联网上有很多例子



< a href > http://www.akadia.com/services/dotnet_read_write_blob.html [ ^ ]
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[^]