带有C#sqlserver2005本地主机映像的ASP.NET不存储 [英] Asp.net with c# sqlserver2005 local host image not store

查看:61
本文介绍了带有C#sqlserver2005本地主机映像的ASP.NET不存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计我的网页,我想要存储图像位置,然后进行客户记录,我正在做照相馆管理工作室系统图像位置而不是存储...

I''m designing my web page i want store image location and then customer record i am doing photo studio management studio system image location not store...

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)
        {
            string filename = Server.MapPath("~/photo") + FileUpload.PostedFile.FileName;
            FileUpload.PostedFile.SaveAs(filename);
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString =@"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.VarChar).Value = filename;
                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();
            }
        }
    }
}



我的错误
页面已运行.我已单击浏览器控件,选择一个文件窗口,打开,选择照片文件夹,但路径正确.



My error
page is run .i have click the browser controle choose a file window open select the photo folder but path is in correct

推荐答案

您必须将Systemurl字段更改为' '二进制'
you have to change your Systemurl field to ''Binary''


嗨 当您只想存储图像路径时,为什么要使用图像流.
只需从发布的文件中获取图像路径(绝对路径),然后将图像保存在temp文件夹(可选)中,然后将图像路径保存到数据库中即可.
假设您的图像的路径为c:\ picture \ hen.jpeg,则绝对路径变为hen.jpeg,您可以存储绝对路径,并在项目中的任何位置使用它.

谢谢.
巴尔旺(Balwant)
hi when you want to store only the image path then why you used the image stream.
just get the image path(absolute path) from the posted file and save the image in the temp folder(optional) and save the image path into the database.
suppose your image has path c:\picture\hen.jpeg the the absolute path becomes hen.jpeg and you can just store the absolute path and make use of it any where in your project.

Thanks.
Balwant


public void onflbload(object sender, EventArgs e)
        {
            
      
string filename=Server.MapPath("~\YourUploadFolder")+FileUpload.PostedFile.FileName;
FileUpload.PostedFile.SaveAs(filename);
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString =@"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.VarChar).Value = filename;
                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();
            }
        }



检查代码是否有效.



Check whether the code works.


这篇关于带有C#sqlserver2005本地主机映像的ASP.NET不存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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