html - How to upload image to a database using webmatrix 3? -


i have 2 different cshtml pages. 1 creating database , second 1 showing data. don't know how upload image. every time upload png file , says "4 : unable cast object of type 'system.string' type 'system.byte[]'." datatype in database image

here code:

@{ var productname=""; var productprice=""; var productexpiredate=""; var productdescription=""; var productimage="";   productname=request["pname"];   productprice=request["price"];   productexpiredate= request["expiredate"];   productdescription= request["description"];   productimage = request["image"]; if(ispost){ var sqlinsert = "insert productinfo (name, price, expiredate, description, image) values (@0,@1,@2,@3,@4)"; var db = database.open("product"); db.execute(sqlinsert, productname , productprice, productexpiredate, productdescription, productimage); //response.redirect("default.cshtml"); } }  <!doctype html> <html lang="en">     <head>         <meta charset="utf-8"/>         <title> maxproducts </title>     </head>    <body>         <div id="addproducts">             <h2>  product information </h2>                 <form action="" method="post" name="productsform" >                   name:<br>                   <input type="text" name="pname"><br>                   price:<br>                   <input type="text" name="price"><br>                   expire date:<br>                   <input type="date" name="expiredate"><br>                   description:<br>                   <textarea rows="10" cols="80" name="description">                         </textarea><br>                        image:<br>                   <input type="file" name="image"><br><br>                   <input type="submit" value="enter product" name="enterproduct"/><br>             </form>         </div>     </body> </html> 

not 100% sure correct solution, have done when uploaded videos database, set file name database, , when need pull database use variable pull video.

@foreach (var title in db.query("select * vids" )){     var toopen="media/"+title.title;     <div id="item" class="playerdiv" onclick="window.open('@toopen','mywin','width:200px'); ">         <div style="margin: 10px">@renderpage("thumbplayer.cshtml", new { title=title.title               })</div>     </div> 

then when clicks on image opens in new window. it's not elegant works me.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -