[英]How to insert image into database using razor(asp.net)
I am working on web pages(razor) asp.net using Webmatrix environment. 我正在使用Webmatrix环境在webpages(razor)asp.net上工作。 I am trying to insert uploaded image path into database so i confuse which variable should be pass to query to make the path inserted into table.
我正在尝试将上传的图像路径插入数据库,因此我混淆了应该将哪个变量传递给查询以将路径插入表中。 here is my code:
这是我的代码:
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)));
}
}
}
To store image in database you just need insert particular image location (in the form of string) on the server of your image into database table. 要将图像存储在数据库中,您只需要将图像服务器上的特定图像位置(以字符串形式)插入数据库表即可。
for example: to store "photo.jpg" in the database first upload it to your server, next get the path of image at your server, save the path in the database table(ex: INSERT INTO table_name VALUES (....,Path,...);) 例如:要将“ photo.jpg”存储在数据库中,首先将其上传到服务器,然后在服务器上获取图像的路径,然后将该路径保存在数据库表中(例如:INSERT INTO table_name VALUES(....,路径,...);)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.