图片位置未保存 [英] The image location not stored

查看:74
本文介绍了图片位置未保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有商店图像,然后有客户详细信息,但是数据库表存储在图像位置(路径)中,但是商店图像位置为……".此类型是否存储正确?但不能只存储图像位置,例如(D:documentsetting \"k.jpeg)我希望此类型存储任何更改的任何代码

i have store image and then customer details but database table store in image location (path)but store image location is �က䙊䙉Āā䠀䠀 this type are stored is it correct? but no currect only store image location EXAMPLE (D:documentsetting\"k.jpeg) i want this type are store any change any code

namespace photoshops
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            onflbload(sender, e);
        }
        
           public void onflbload(object sender, EventArgs e)
        {
            // Create a byte[] from the input file
            int len = flbload.PostedFile.ContentLength;
            byte[] pic = new byte[len+1];
            flbload.PostedFile.InputStream.Read(pic, 0, pic.Length);
            // Insert the image and comment into the database
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString =@"Data Source=DEVI\SQLEXPRESS; Initial Catalog =cat; Integrated Security=true";
               
            try
            {
                connection.Open();
                SqlCommand cmd = new SqlCommand("insert into tblphotosettings "
                 + "(BillNo,CustomerName,Address,StartDate,EndDate,Systemurl,Numberofcopies,Amount,Total ) values (@BillNo,@CustomerName,@Address,@StartDate,@EndDate,@Systemurl,@Numberofcopies,@Amount,@Total)", connection);
                cmd.Parameters.Add(new SqlParameter("@BillNo", TextBox1.Text));
                cmd.Parameters.Add(new SqlParameter("@CustomerName", TextBox2.Text));
                cmd.Parameters.Add(new SqlParameter("@Address", TextBox3.Text));
                cmd.Parameters.Add(new SqlParameter("@StartDate",Rdbsdate.SelectedDate));
                cmd.Parameters.Add(new SqlParameter("@EndDate", Rdbddate.SelectedDate));
                cmd.Parameters.Add(new SqlParameter("@Systemurl",pic));
                cmd.Parameters.Add(new SqlParameter("@Numberofcopies", TextBox7.Text));
                cmd.Parameters.Add(new SqlParameter("@Amount", TextBox8.Text));
                cmd.Parameters.Add(new SqlParameter("@Total", TextBox9.Text));
                cmd.ExecuteNonQuery();
            }
            
            finally
            {
                connection.Close();
            }
        }
    }
}

推荐答案

cmd.Parameters.Add(new SqlParameter("@Systemurl",pic));


您已将pic作为参数传递.现在检查图片中包含什么-


You have passed pic as the parameter. Now check what pic contains -

byte[] pic = new byte[len+1];
flbload.PostedFile.InputStream.Read(pic, 0, pic.Length);



它包含您上传的文件.您如何期望它包含存储图像的路径?

如果需要将文件保存到磁盘并将其路径保存在数据库中,请首先将文件保存在Web应用程序根文件夹内的子文件夹中.然后使用MapPath函数获取服务器上的相关路径并将该路径保存在数据库中.
网上有很多例子.我想搜索Google并尝试一下! :thumbsup:



It contains your uploaded file. How do you expect it to contain the path of the stored image?

If you need to save the file to a disk and save it''s path in the database, you first save the file in a sub-folder inside your web-application root folder. Then use MapPath function to get the relevant path on the server and save that path in the database.
There are so many examples available on the web. I want to search Google and give it a try! :thumbsup:


这篇关于图片位置未保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆