Update image using Datalist control and Sqldatasource

peter liles 556 Reputation points
2022-08-28T20:58:46.007+00:00

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()

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,234 questions
0 comments No comments
{count} votes

Accepted answer
  1. QiYou-MSFT 4,306 Reputation points Microsoft Vendor
    2022-08-29T09:43:52.573+00:00

    Hi @peter liles ,
    You can try setting parameters in an update event.
    Maybe you can provide detailed error messages and codes.
    https://learn.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.


0 additional answers

Sort by: Most helpful