Hpload an image into SQL Server database using c# and asp.net -


before ask question want have gone through lot of other similar questions , didn't that's why decided ask mine.

ok, i'm trying upload selected image database when upload button clicked, front-end written in asp.net , back-end in c#.

this code:

if (fileupload1.hasfile) {     sqlconnection con = new sqlconnection("i put connection string here");     con.open();      int length = fileupload1.postedfile.contentlength;     byte[] pic = new byte[length];      fileupload1.postedfile.inputstream.read(pic, 0, length);      sqlcommand com = new sqlcommand("insert loghelp (file) values (@image)", con);     com.parameters.addwithvalue("@image", pic);      com.executenonquery();      con.close(); } 

now i'm using visual studio 2015 web form. when run code above, throws error:

an exception of type 'system.data.sqlclient.sqlexception' occurred in system.data.dll not handled in user code

additional information: incorrect syntax near keyword 'file'.

please mean? , if have way can use accomplish same task please i'm ears.

i've since tested hypothesis put forward in comment:

you need surround file square brackets - file keyword in sqlserver

insert loghelp([file]) values(@image) 

i disagree other commenter; i'm of opinion no database system i've used needs have space between end of table name , opening bracket listing columns insert into. do, concur observation there no need write sql 2 strings concatenated ("insert..."+" values...") in code though

consider not getting addwithvalue habit, reasons set out here: https://blogs.msmvps.com/jcoehoorn/blog/2014/05/12/can-we-stop-using-addwithvalue-already/


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -