如题,最好是把代码贴出来,感激不尽!!

解决方案 »

  1.   

    很详细了,自己看吧
    http://www.cnblogs.com/oec2003/archive/2010/01/06/1640027.html
      

  2.   

    你将图片保存到数据库字段中???你不早说,数据库字段设置成Image或Text类型。
    以下是保存图片到数据库的例子,获取到上传图片,然后将其转换成字节数组,然后保存到数据库的Image或Text类型字段中。http://www.cnblogs.com/xiaoyao2011/archive/2011/09/25/2189999.htmlhttp://www.cnblogs.com/drek_blog/archive/2009/06/13/1502594.html
      

  3.   

    - -!保存到数据库不就是一句insert 语句?你的数据库的表怎么设计 关键是比如你需要文件编号 文件名称 文件路径 上传时间等等..
    然后上传的时候获取这些变量 然后insert into ...
      

  4.   

    我以前用uploadify,得意于这个链接,保存到数据库表示无压力
      

  5.   

    哎,還是搞错了,没看清楚我的标明啊,我是想用uploadify这个插件来上传图片,然后保存到数据库,当然,我指的是把上传图的路徑保存到数据库。。
      

  6.   

    这位哥们也没看清楚标题啊,我说的是用uploadify这个插件来上传图片,然后把图片的路徑保存到数据库,关键是怎么在后台得到uploadify上传图片后的路徑!
      

  7.   

    。。是你自己想复杂了 你获取到你需要保存的字段 然后insert不就可以了 晕
      

  8.   

    #region    上传文件到数据库和服务器
            public void FN_UpFiles()
            {            //遍历File表单元素
                HttpFileCollection files = HttpContext.Current.Request.Files;
                for (int iFile = 0; iFile < files.Count; iFile++)
                {
                    //检查文件扩展名字
                    HttpPostedFile postedFile = files[iFile];
                    string fileName = "";//定义文件名
                    //string fileExtension = "";
                    fileName = Path.GetFileName(postedFile.FileName);//得到上传文件的完整名称 即文件名+后缀名
                    int index = fileName.IndexOf(".");
                    string FileType = fileName.Substring(index).ToLower();//截取文件后缀名
                    //FileTypeImg = "../FileTypeimg/" + hz + ".gif";
                    Guid fileGuid = Guid.NewGuid();//生成新的文件名称 以GUID命名防止文件名相同
                    string NewFileName = fileGuid.ToString();//新的文件名
                    NewFileName = NewFileName + FileType;//新的文件名+后缀名                if (fileName != "")//如果文件名不为空
                    {                    //文件虚拟路径
                        string strpath = System.Web.HttpContext.Current.Server.MapPath("~/Upload/") + NewFileName;
                        try
                        {
                            NRModel.File model = new NRModel.File();
                            NRBLL.File bf = new NRBLL.File();
                            Guid guid1 = Guid.NewGuid();
                            Guid guid2 = new Guid(FolderId);
                            Guid guid3 = Guid.NewGuid();
                            Guid guid4 = Guid.NewGuid();
                            model.Fileid = guid1;
                            model.Folderid = guid2;
                            model.Filepath = strpath;
                            model.FileNam = fileName;
                            model.FileSize = postedFile.ContentLength;
                            model.Decription = this.TextArea1.Value.ToString();
                            model.CreateOn = DateTime.Now;
                            model.CreateBy = guid3;
                            model.ModefyBy = guid4;
                            if (bf.FN_AddNewRes(model) > 0)
                            {
                                NR.Error.Log.LogType("上传资源" + fileName + "成功!" + "服务器路径:" + strpath);
                                //保存文件到指定目录(虚拟目录)
                                postedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath("~/Upload/") +NewFileName);
                                Page.RegisterStartupScript("提示", "<script language='javascript'>alert('上传成功!');self.opener.location.reload();window.close();</script>");
                            }
                        }
                        catch (Exception ex)
                        {
                            NR.Error.Log.LogType(ex.ToString());
                        }
                    }
                }
            }
        }
            #endregion
    参考
      

  9.   

    HttpPostedFile file= context.Request.Files["file1"];
    BinaryReader b = new BinaryReader(file.InputStream);
    byte[] binaryData = b.ReadBytes(file.InputStream.Length);
    sql = "Insert into tableName (img) values(@img)"cmd.Parameters.AddWithValue("@img",binaryData )
      

  10.   

    版主 你的这句报错啊
    System.IO.BinaryReader.ReadBytes(int)最匹配的重载方法具有一些无效参数
    byte[] binaryData = b.ReadBytes(file.InputStream.Length);
      

  11.   


    byte[] binaryData = br.ReadBytes((Int32)file.InputStream.Length);
    我给它强制转换了一下可以了
    SqlConnection myConnection = new SqlConnection(conString);
                myConnection.Open();            SqlTransaction myTrans = myConnection.BeginTransaction();
                SqlCommand myCommand = new SqlCommand();
                myCommand.Connection = myConnection;
                myCommand.Transaction = myTrans;            try
                {
                    myCommand.CommandText = "insert into image(body)values(" + @binaryData+");";
                    myCommand.ExecuteNonQuery();
                    myTrans.Commit();
                    Console.Write("执行成功!");
                    Console.Read();
                }然后我这么插入到表里面就报错,body是image类型的
    然后报这个错误:
    缺少对象或列名,或者对象或列名为空。对于 SELECT INTO 语句,请确保每列均具有名称。对于其他语句,请查找空的别名。不允许使用定义为 "" 或 [] 的别名。请添加名称或单个空格作为别名。 
    在此上下文中不允许使用名称 "System.Byte"。有效表达式包括常量、常量表达式和变量(在某些上下文中)。不允许使用列名。
      

  12.   

    上传成功 sql语句写错了,而且没替换参数
      

  13.   

    myCommand.CommandText = "insert into image(body)values(" + @binaryData+");";
    这么写是错误 的。必须写myCommand.CommandText = "insert into image(body)values(@xx)";
    myCommand.Parameters.AddWithValue("@xx", binaryData);