I have a Telerik RadBinaryImage control which is displaying an image loaded using Telerik RadAsyncUpload.
I have an SQL table containing a 'Photo' column (image data type). I want to save to the database the image from the Telerik RadBinaryImage to the insert function which look like this:
Private Sub InsertPhotoIntoDB()
Dim sMyConn As String = My.Settings.appDBConnString
Dim myConnection As SqlConnection
Dim myCommand As New SqlCommand
myConnection = New SqlConnection(sMyConn)
myConnection.Open()
myCommand = New SqlCommand("INSERT INTO Photos(Photo) VALUES(@Photo)")
myCommand.Connection = myConnection
myCommand.Parameters.Add("@Photo", SqlDbType.Image, 0, "Photo")
myCommand.Parameters("@Photo").Value = WhatDoIPutHere???
myCommand.ExecuteNonQuery()
myConnection.Close()
myConnection.Dispose()
End Sub
I've tried:
myCommand.Parameters.Add("@Photo", SqlDbType.Image).Value = RadBinaryImage1.DataValue
but I still get an error:
The parameterized query '(@Photo image)INSERT INTO Photos (Photo) VALUES (@Photo)' expects parameter '@Photo', which was not supplied.
Do I need to convert RadBinaryImage1.DataValue to image?
The safest way is to upload the image as a byte array:
How to get to a byte array differs. With the ASP.NET Upload control, it's just:
Or if the image is represented as a stream: