错误尝试添加文件名,结束串的:错误试图添加文件名,结束串的:
if (FileUploadControl.HasFile)
{
try
{
string theUserId = Session["UserID"].ToString();
OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite2; User=root; Password=commando;");
cn.Open();
string filename = Path.GetFileName(FileUploadControl.FileName);
string fileuploadpath = Server.MapPath("~/userdata/" + theUserId + "/uploadedimage/") + filename);
// error on this line filename only assignment, call can be used as a statement
FileUploadControl.SaveAs(Server.MapPath(fileuploadpath));
StatusLabel.Text = "Upload status: File uploaded!";
OdbcCommand cmd = new OdbcCommand("INSERT INTO Pictures (UserID, picturepath) VALUES ('" + theUserId + "' , '" + fileuploadpath + "')", cn);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
}
}
如果我试着这样说:
string fileuploadpath = Server.MapPath("~/userdata/" + theUserId + "/uploadedimage/");
FileUploadControl.SaveAs(Path.Combine(fileuploadpath, filename));
我得到一个MySQL错误的没有文件名添加到路径的末尾(顺便说一句,只是试图保存路径不是图像)虽然技术上我应该仍然能够插入一半的文件路径到SQL中,所以也许这个错误与我的原始上传方法没有关系上面的代码。但显然我仍然需要完整的路径名。
无法上传文件。出现以下错误:错误[42000] [MySQL] [ODBC 3.51驱动程序] [mysqld-5.5.9]您的SQL语法错误;检查与您的MySQL服务器版本相对应的手册,以在第1行'C:\ Users \ Garrith \ Documents \ Visual Studio 2010 \ WebSites \ WebSite1 \ userdata \ 1 \ uplo'附近使用正确的语法。
好吧,这有助于映射的路径,但我仍然在我的字符串文件的上传路径的末尾+文件名中出现错误? – 2011-03-25 10:57:48
你能解释一下这个错误吗?你现在面临的那个错误的细节是什么? – 2011-03-26 08:57:52