Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Guys,

please help me with this, im having this error, when im trying to insert a file in my fileupload. It then prompts something, below is the code i wrote and the error message is on bold. the datatype i used for the productimg column is image.

row["prodcutimg"] = Fileuploadd1.FileName.ToString(); ----type of value has a mismatch with column type couldn't store <picture002,jpg> in productimg column. Expected type is Byte[]
Posted

1 solution

The error message is pretty explicit: it expects an array of bytes, and you are passing a string.
If you want to pass the file content, then you are doing the wrong thing anyway: that will only pass the name of the file, not the actual data the file contains.
Try:
C#
byte[] filedata = Fileuploadd1.FileBytes;
row["prodcutimg"] = filedata;
 
Share this answer
 
Comments
Member 10302214 8-Oct-13 12:17pm    
Thanks for the answer sir, it helped. but in my datalist view, the image is not showing. it is only stated "System.Byte[]". What seems to be the problem?
OriginalGriff 8-Oct-13 12:34pm    
Hah! That's actually how you did the insert to the DB. Now, answer this question: Have you ever heard of SQL Injection Attacks?
Because that is what you are risking every single time you do anything with your database...
How do I know? Simple: you are concatenating strings to form you SQL command, and I don;t need to see your code to know that, because it's also the source of this problem.
See here:
http://www.codeproject.com/Tips/465950/Why-do-I-get-a-Parameter-is-not-valid-exception-wh
It will explain what to do, and why.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900