Hi,
I am using objectdatasource as datasource in page. I use the "File Upload" control to get the image and save to database. Within the database table, there are a lot of datafield. I got the problem of setting the parameter value for the image. I use three datafield to store the image relevant data.
Datafield DataType
1. imgName (nvarchar 50)
2. imgData (Image)
3. imgType (nvarchar 50)
Question
1: How can I set the "value" to the parameter?
2. Do I make mistake to the image field, since declare in database is "Image" datatype and use "Byte" in codebehind?
3: For next time if user want to retrieve the image, can it be "restore" as "image file"?
4. Can I use the "File Upload" control in "DetailsView" with objectdatasource? Because I have try to do it, but unsuccessful. Since I use the "Template Field" and drag the "File Upload" control to the "InsertItemTemplate", but there is no bound property of "text" which to bound to the "field binding". So, is this possible to use "file upload" control in DetailsView?? If so, how to do It.
5. With the approach in question 4, the DetailsView was include in the "atlas:UpdatePanel", will this make error?
Appreciate for those giving solution and help.
Calvin
I am using objectdatasource as datasource in page. I use the "File Upload" control to get the image and save to database. Within the database table, there are a lot of datafield. I got the problem of setting the parameter value for the image. I use three datafield to store the image relevant data.
Datafield DataType
1. imgName (nvarchar 50)
2. imgData (Image)
3. imgType (nvarchar 50)
Code:
Try
Dim imgName As String
Dim imgContentType As String
Dim imgLen As Int32
Dim imgbin() As Byte
If Me.FileUpload.HasFile = True Then
If Me.FileUpload.PostedFile.FileName.Trim.Length > 0 And Me.FileUpload.PostedFile.ContentLength > 0 Then
Dim imgStream As Stream = Me.FileUpload.PostedFile.InputStream()
imgLen = Me.FileUpload.PostedFile.ContentLength
imgContentType = Me.FileUpload.PostedFile.ContentType
imgName = Me.FileUpload.PostedFile.FileName.Substring(Me.FileUpload.PostedFile.FileName.LastIndexOf("\") + 1)
Dim imgBinaryData(imgLen) As Byte
Dim n As Int32 = imgStream.Read(imgBinaryData, 0, imgLen)
imgbin = imgBinaryData
ObjectDataSource.InsertParameters("imgName") = imgName
ObjectDataSource.InsertParameters("imgData") = imgbin
ObjectDataSource.InsertParameters("imgType") = imgContentType
ObjectDataSource.Insert()
1: How can I set the "value" to the parameter?
2. Do I make mistake to the image field, since declare in database is "Image" datatype and use "Byte" in codebehind?
3: For next time if user want to retrieve the image, can it be "restore" as "image file"?
4. Can I use the "File Upload" control in "DetailsView" with objectdatasource? Because I have try to do it, but unsuccessful. Since I use the "Template Field" and drag the "File Upload" control to the "InsertItemTemplate", but there is no bound property of "text" which to bound to the "field binding". So, is this possible to use "file upload" control in DetailsView?? If so, how to do It.
5. With the approach in question 4, the DetailsView was include in the "atlas:UpdatePanel", will this make error?
Appreciate for those giving solution and help.
Calvin
Last edited by a moderator: