文件上传
这是我做的一个简单的文件上传程序,报错 “ 将截断字符串或二进制数据。语句已终止”if (FileUpload1.PostedFile.FileName == "")
{
Response.Write("<script language=javascript>alert('上传文件不允许为空!')</scrpit>");
}
else
{
//string ss;//ss = System.DateTime.Now.ToString().Replace("-", "").Replace(" ", "").Replace(":", "") + Path.GetExtension(FileUpload1.PostedFile.FileName);
string filepath = FileUpload1.PostedFile.FileName;
string filename = filepath.Substring(filepath.LastIndexOf("\\")+1);
string fileextend = filepath.Substring(filepath.LastIndexOf(".") + 1).ToLower();
string serverpath = Server.MapPath("up/")+filename;
FileUpload1.PostedFile.SaveAs(serverpath);
SqlConnection con = new SqlConnection("server=.;database=pubs;uid=sa;pwd=;");
con.Open();
string sqlstr = "insert into files([name],fileload) values ('"+filename+"','"+serverpath+"')";
//SqlCommand cmd = new SqlCommand("insert into files(name,fileload) values ('" + filename + "," + serverpath + "')", con);
SqlCommand cmd=new SqlCommand(sqlstr,con);
cmd.ExecuteNonQuery();//在这地方报错
con.Close();
Response.Write("<script language=javascript>alert('上传文件成功!')</script>");
}
}