Saving an image into a database from a dataset
-
I already build a table inside a dataset. The rows of the table consist of basic varchar and integer columns accept for a binary column.(My image problem) I want to write the rows as whole into the my sql database from the dataset. I would really appreciate it if any can help me with this problem. If possible I would like to use a stored procedure to solve this problem Regardt
-
I already build a table inside a dataset. The rows of the table consist of basic varchar and integer columns accept for a binary column.(My image problem) I want to write the rows as whole into the my sql database from the dataset. I would really appreciate it if any can help me with this problem. If possible I would like to use a stored procedure to solve this problem Regardt
I ran into a problem inserting/updating images through a stored procedure, I think because of a limit to the size of data sent through a stored procedure parameter. To solve this problem, I execute inserts and updates directly, like this:
Public Function Insert(ByVal imageData As Byte(), ByVal imageType As String) As Integer Dim cmdText As String = "INSERT INTO MyImages(Image, ImageType) VALUES(@image, @imageType) SELECT SCOPE_IDENTITY()" Dim args(1) As SqlParameter args(0) = New SqlParameter("@image", imageData) args(1) = New SqlParameter("@imageType", imageType) Try Return CInt(SqlHelper.ExecuteScalar(ConnectionString, CommandType.Text, cmdText, args)) Catch ex As SqlException ' do error handling Throw End Try End Function
NOTE: I'm using the Microsoft Data Access Application Block[^] (SqlHelper) for data access. -
I ran into a problem inserting/updating images through a stored procedure, I think because of a limit to the size of data sent through a stored procedure parameter. To solve this problem, I execute inserts and updates directly, like this:
Public Function Insert(ByVal imageData As Byte(), ByVal imageType As String) As Integer Dim cmdText As String = "INSERT INTO MyImages(Image, ImageType) VALUES(@image, @imageType) SELECT SCOPE_IDENTITY()" Dim args(1) As SqlParameter args(0) = New SqlParameter("@image", imageData) args(1) = New SqlParameter("@imageType", imageType) Try Return CInt(SqlHelper.ExecuteScalar(ConnectionString, CommandType.Text, cmdText, args)) Catch ex As SqlException ' do error handling Throw End Try End Function
NOTE: I'm using the Microsoft Data Access Application Block[^] (SqlHelper) for data access.