3

I want to add a image file to my database using sqldatasource .

steps that i have taken

1.Coverting image to Byte[] array.

Stream fs = FileUpload1.PostedFile.InputStream; 
BinaryReader br = new BinaryReader(fs); 
Byte[] bytes = br.ReadBytes((Int32)fs.Length); 

2.Setting the update parameter type as Object

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

3.Adding byte array as update parameter in SqlDataSource control.

sqlDataSource.UpdateParameters["File"].DefaultValue = bytes;

but when i compile this code it is giving me a error "is giving me a error

"Cannot Implicitly convert byte[] to string" at third step

2 Answers 2

3

Try to set parameter in Updating event

private void sqlDataSource_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
    e.Command.Parameters["File"].Value = bytes;
}
Sign up to request clarification or add additional context in comments.

Comments

0

you should make data type varbinary

and made datatype varbinary(max) in your database

1 Comment

you can only enter string type value to the DefaultValue .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.