我已做了一个上传图片的功能,只是将图片保存到数据库中了!我现在不想保存到数据库中,只想把上传的路径保存到数据库里,请问如何做。如果有源码更好!!!谢谢因为本人是新手!!!!或者给个下载例题的链接。谢谢!!!!

解决方案 »

  1.   

    给你提供一个上传图书信息的代码,希望对你有用。原理是先把图书信息插入数据库中,然后读出他的id号,再把你要上传的图片的名字命名为id的值。把图片的路径做一些更改,然后把路径插入到数据库中,以后直接把路径绑定到图片的url上就可以了        if ((upfile.PostedFile.ContentLength > 0) && (upfile.Value.ToString() != ""))
            {
                //将名字插入到数据库,并取出该名字对于的id,把这个id作为要上传的图片的名字
                string product = this.textName.Text.ToString();
                string price = this.textPrice.Text.ToString();
                string content = this.textContent.Text.ToString();
                price = "单价:" + price + "元";
                SqlConnection con = new SqlConnection("server=.;uid=admin;pwd=pass;database=BookShopDB");
                con.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandText = "insert into product (product,productPrice,productNotes) values('"+product+"','"+price+"','"+content+"')";
                
                cmd.ExecuteNonQuery();            SqlCommand dd = new SqlCommand();
                dd.Connection = con;            dd.CommandText = "select id from product where product='"+product+"'";            string id = Convert.ToString(dd.ExecuteScalar());
                
               
                           //获取上传文件的后缀名
                string suffix = upfile.PostedFile.FileName.Substring(upfile.PostedFile.FileName.LastIndexOf("."));            //获取存放图片的文件夹的路径
                string uploadpath = this.Server.MapPath("uploadefile");            //获取文件名
                string tempFileName = upfile.PostedFile.FileName.Substring(upfile.PostedFile.FileName.LastIndexOf("\\") + 1);       
                
                //  -----------------------------------
                //获取文件的绝对存放路径
             //   fileSavePath = fileSavePath.Substring(fileSavePath.LastIndexOf(":") + 1);
             //   fileSavePath = fileSavePath.Replace("\\", "/");         // -------------------------------            //文件的存放路径
                string fileSavePath = uploadpath + "\\" + id + suffix;
                upfile.PostedFile.SaveAs(fileSavePath);           // ---------------------------            fileSavePath = fileSavePath.Substring(fileSavePath.LastIndexOf(":") + 1);
                fileSavePath = fileSavePath.Replace("\\", "/");            //-----------------------------
                //将图片的路径插入到数据库中去
                Response.Write(fileSavePath);            SqlCommand smd = new SqlCommand();
                smd.Connection = con;
                smd.CommandText = "update product  set path= '" + fileSavePath + "'where id='" + id + "'";            smd.ExecuteNonQuery();
                con.Close();
            
                
      

  2.   

    我在网上下了好多源码程序,可以全部都是编译成dll文件的,关键的代码看不到!!!急啊!!
    请教!!!
    分不够再加!!!