c# - How do I insert an image into a database? -


public void insertanimage(guid i) {     stringbuilder sb = new stringbuilder();      sb.append("");      stream stream = fileupload1.filecontent;     streamreader reader = new streamreader(stream);      string myconnectionstring = allquestionspresented.connectionstring;     using (sqlconnection conn = new sqlconnection(allquestionspresented.connectionstring))     {         // sample query parameters insert db         string sqlquery = "insert [userprofile] (userid, picture) values (@userid, @picture)";         // conn db connection         sqlcommand command = new sqlcommand(sqlquery, conn);         // creating parameters         sqlparameter paramid = new sqlparameter("@userid", sqldbtype.int, 4);         paramid.value = 45;         // picture parameter, , assigning value         sqlparameter parampicture = new sqlparameter("@picture", sqldbtype.binary, myimage.length);// red line here         parampicture.value = myimage;// red line here         // adding params command         command.parameters.add(paramid);         command.parameters.add(parampicture);         // execute command         command.executenonquery();     } } 

how put streamreader instead of filestream reader database?

here's article:

save , retrieve images database using asp.net 2.0 , asp.net 3.5

however, general consensus it's better store image in file system.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -