图片文件路径未存储如何更改 [英] picture filepath not stored how to changed

查看:82
本文介绍了图片文件路径未存储如何更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

namespace photo
  {
    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];
        flbload.PostedFile.InputStream.Read(pic, 0, len);
        // Insert the image and comment into the database
        SqlConnection connection = new SqlConnection(@"Data Source=DEVI\SQLEXPRESS; 
                          Initial Catalog =cat; Integrated Security=SSPI");
        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("@BillNo", SqlDbType.NVarChar).Value = TextBox1.Text;
            cmd.Parameters.Add("@CustomerName", SqlDbType.NVarChar).Value =TextBox2.Text;
            cmd.Parameters.Add("@Address", SqlDbType.NVarChar).Value = TextBox3.Text;
            cmd.Parameters.Add("@StartDate", SqlDbType.NVarChar).Value =Rdbsdate.SelectedDate;
            cmd.Parameters.Add("@EndDate", SqlDbType.NVarChar).Value =Rdbddate.SelectedDate;
            cmd.Parameters.Add("@Systemurl", SqlDbType.Image).Value = pic;
            SqlParameter Src = new SqlParameter("@FilePath", SqlDbType.VarChar, 450);
            cmd.Parameters.Add(Src);
            cmd.Parameters.Add("@Numberofcopies", SqlDbType.NVarChar).Value =TextBox7.Text;
            cmd.Parameters.Add("@Amount", SqlDbType.NVarChar).Value = TextBox8.Text;
            cmd.Parameters.Add("@Total", SqlDbType.NVarChar).Value = TextBox9.Text;
            cmd.ExecuteNonQuery();
        }
        finally
        {
            connection.Close();
        }
    }
}
}

我的错误
参数化查询``(@BillNo nvarchar(2),@ CustomerName nvarchar(2),@ Address nvarchar''期望未提供参数``@FilePath''.

解决方案

由于您的代码与其他人昨天发布的代码相同,因此,我仅向您指出为他解决的问题的答案:[Repost]图片文件名未存储 [

My Error
The parameterized query ''(@BillNo nvarchar(2),@CustomerName nvarchar(2),@Address nvarchar'' expects the parameter ''@FilePath'', which was not supplied.but iwant imagefile path how to change in my code

解决方案

Since your code is identical to the code posted yesterday by someone else, I will just point you to the answer which fixed it for him: [Repost] image file name not stored[^]


The variable pic is a byte array and it does not have a method GetName. You are trying to use that here:

Src.Value = pic.GetName();



You should get the file name from the FileUpload control you are using and manually append the path where you are saving in the server.

Update: You have to provide the file name. You are not doing that. You should get it from the FileUpload control and then set it as the value for fileName parameter.


这篇关于图片文件路径未存储如何更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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