question

peterliles-4155 avatar image
0 Votes"
peterliles-4155 asked peterliles-4155 commented

Update image using Datalist control and Sqldatasource

In the UpdateCommand event i am trying to update a image in Datalist edittemplate. The problem is bmpBytes is a byte array and sql updateparameter declaration<asp:Parameter Name="Data" DbType="Binary" /> will not accept it in this format only string. My database type is set to Image.
The system responds with cannot convert from string to image.


VanImagesSqlDataSource.UpdateParameters("Data").DefaultValue = bmpBytes
VanImagesSqlDataSource.Update()

dotnet-aspnet-webpages
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

QiYou-MSFT avatar image
0 Votes"
QiYou-MSFT answered peterliles-4155 commented

Hi @peterliles-4155,
You can try setting parameters in an update event.
Maybe you can provide detailed error messages and codes.
https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.sqldatasource.updating?redirectedfrom=MSDN&view=netframework-4.8

 private void sqlDataSource_Updating(object sender, SqlDataSourceCommandEventArgs e)
 {
     e.Command.Parameters["File"].Value = bytes;
 }



Setting the update parameter type as Object

 <UpdateParameters>       
 <asp:Parameter Name="File" Type="Object" />
 </UpdateParameters>

Best regards,
Youqi


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.




· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Yes that example was helpful. The problem with using update event is getting all the values. I finally managed to retrieve from datalist and add them to the command as explained. The difficulty with original way was parameters take string data and image is in bytes! so will not compute even when convert to .String method type.

0 Votes 0 ·