面对错误:找不到路径;在插入数据和在数据库中保存路径期间 [英] Facing Error: Couldn't Find Path; During insertion of data and saving Path in Database

查看:86
本文介绍了面对错误:找不到路径;在插入数据和在数据库中保存路径期间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个简单的Insert,Fetch Web应用程序。插入数据时,我将图像保存到文件夹〜/ Photos /及其在数据库中的路径,但得到错误:



System.IO。 DirectoryNotFoundException:找不到路径'C:\ Users \Vipin \Documents\Visual Studio 2010 \WebSites \NNSEnrollment \Photos \'的一部分。



文件夹位于其定义的目录。

我的代码是:

尝试

{

string filename = FileUpload1.FileName;



FileUpload1.PostedFile.SaveAs(Server。 MapPath(〜\\Photos\\+ filename.Trim()));



string path =〜\\Photos \\ \\\+ filename.Trim();





str =插入spouse_details(r_p_id,name,dob,contact, marriage_anniversary_date,image_path)values('+ Convert.ToInt16(lbl_r_p_id.Text)+','+ txt_name_spouse.Text +','+ Convert.ToDateTime(txt_sp_dob.Text)+','+ txt_contact .Text +','+ Convert.ToDateTime(txt_anniversary.Text)+','+ path +');

dap = new OleDbDataAdapter(str,con);

dt = new DataTable();

dap.Fill(dt);

Response.Writ e(< script> alert('Submit');< / script>);

}



catch(异常) ex)

{

Response.Write(ex.ToString());

}


虽然相同的代码在之前的其他一些应用程序中工作...先谢谢你

I'm working on a simple Insert, Fetch Web application. While inserting data I'm saving Images to the Folder "~/Photos/" and it's path in Database, But getting Error:

System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\Vipin\Documents\Visual Studio 2010\WebSites\NNSEnrollment\Photos\'.

The Folder is at its defined directory.
My Code is:
try
{
string filename = FileUpload1.FileName;

FileUpload1.PostedFile.SaveAs(Server.MapPath("~\\Photos\\" + filename.Trim()));

string path = "~\\Photos\\" + filename.Trim();


str = "insert into spouse_details (r_p_id,name,dob,contact,marriage_anniversary_date,image_path) values('" + Convert.ToInt16(lbl_r_p_id.Text) + "','" + txt_name_spouse.Text + "','" + Convert.ToDateTime(txt_sp_dob.Text) + "','" + txt_contact.Text + "','" + Convert.ToDateTime(txt_anniversary.Text) + "','" + path + "')";
dap = new OleDbDataAdapter(str, con);
dt = new DataTable();
dap.Fill(dt);
Response.Write("<script>alert('Submit');</script>");
}

catch (Exception ex)
{
Response.Write(ex.ToString());
}

Whereas the same code is working in Some other application earlier... Thank You in Advance

推荐答案

所以检查路径并查看文件夹是否在那里。 />
我的猜测是,当你在网站的根目录中创建照片文件夹时,你的名字有误。



哦,你自己做帮助:不要连接字符串来构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。请改用参数化查询。特别是网站,这是非常危险的......
So check the path and see if the folder is there.
My guess is that you got the name wrong when you created the "Photos" folder in the root of your website.

Oh and do yourself a favour: Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead. Particularly with a website, it's extremely dangerous...


这篇关于面对错误:找不到路径;在插入数据和在数据库中保存路径期间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆