2015-07-20 94 views
0

我正在使用Webmatrix環境在網頁(剃鬚刀)asp.net上工作。 我想插入上傳的圖像路徑到數據庫中,所以我混淆了哪個變量應該傳遞查詢,使路徑插入到表中。 這裏是我的代碼:如何使用剃鬚刀插入圖像到數據庫(asp.net)

int numFiles = Request.Files.Count; 
    string fileName=""; 
    if(IsPost) 
    { 
     for(int i =0; i < numFiles; i++) { 
     var uploadedFile = Request.Files[i]; 
      if (uploadedFile != null) 
     { 
     fileName= Path.GetFileName(uploadedFile.FileName); 
     uploadedFile.SaveAs(Server.MapPath(Path.Combine("~/documents/", fileName))); 
     } 
     } 
    } 

Here is my query to insert into database but i dont know what how o insert the path into database. 

int numFiles = Request.Files.Count; 
    string fileName=""; 
    if(IsPost) 
    { 
     for(int i =0; i < numFiles; i++) { 
     var uploadedFile = Request.Files[i]; 
      if (uploadedFile != null) 
     { 
     fileName= Path.GetFileName(uploadedFile.FileName); 
     uploadedFile.SaveAs(Server.MapPath(Path.Combine("~/documents/", fileName))); 
     } 
     } 
    } 

回答

0

存儲圖像數據庫,你只需要你的形象的服務器到數據庫表中插入(在字符串的形式)特定圖像的位置。

例如:以 在首次上傳存儲「photo.jpg」中的數據庫服務器, 在你的服務器下一得到圖片的路徑, 保存在數據庫表(路徑例如:INSERT INTO TABLE_NAME VALUES(....,Path,...);)