protected void Button1_Click(object sender, EventArgs e)
    {
        if (this.FileUpload1.HasFile)
        {
            int i = this.FileUpload1.PostedFile.ContentLength;   //得到上传文件大小
            if (this.FileUpload1.PostedFile.ContentLength > 10485760) //1024*1024*10=10M,控制大小
            {
                Response.Write("<script>alert('文件不能超过10M !')</script>");
                return;
            }
            string fileName = this.FileUpload1.FileName;
            this.FileUpload1.PostedFile.SaveAs(Server.MapPath("~/") + "\\File\\" + fileName);//把文件上传到根目录的File文件夹中
            SqlConnection myCon = new SqlConnection();
            myCon.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            myCon.Open();
            //2 实例化一个SqlCommand对象
            SqlCommand myCom = new SqlCommand();            //3 利用修改命令赋值SqlCommand的CommandText
            myCom.Connection = myCon;
            myCom = "insert into file(fileLoad,fileName) Values('" + this.FileUpload1.PostedFile.SaveAs(Server.MapPath("~/") + "\\File\\" + fileName) + "','" + this.FileUpload1.FileName + "')";            //4 执行增加记录
            myCom.ExecuteNonQuery();            //5 断开连接
            myCon.Close();            Response.Write("<script language='javascript'>alert('上传文件成功!');location=myfileShare.aspx</script>");        }
    }

解决方案 »

  1.   

    this.FileUpload1.PostedFile.SaveAs(Server.MapPath("~/") + "\\File\\" + fileName)这句SaveAs返回是VOID吧
      

  2.   

    1楼正解你应该在事务中进行处理首先设置上传图片路径
    事务开始:
    {
    string path=Server.MapPath("~/") + "\\File\\" + fileName);
    this.FileUpload1.PostedFile.SaveAs(path);
    myCom = "insert into file(fileLoad,fileName) Values('" + path+ "','" + this.FileUpload1.FileName + "')";
    trans.Commit();
    }
      

  3.   

    正解,保存的绝对路径,事先就弄好,再放进去,SVSE只是保存方法,并不返回路径
      

  4.   

    保存路径应该这样写,string path=Server.MapPath("~/") + "\\File\\" + fileName);
      

  5.   

    this.FileUpload1.PostedFile.SaveAs(Server.MapPath("~/") + "\\File\\" + fileName) + "','" + this.FileUpload1.FileName + "')";括号都没匹配对哦。
      

  6.   

    哦 看错了this.FileUpload1.PostedFile.SaveAs(Server.MapPath("~/")这是个方法
    没返回值 所以累加不上。