图像插入和文件路径 [英] image insert and file path

查看:71
本文介绍了图像插入和文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计我的网页,我希望存储图像位置,然后记录客户记录,我正在执行照相馆管理工作室系统

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

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];
        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);
            Src.Value = flbload.FileName;
            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();
        }
    }
}
}


我的错误
我的错误页面已运行,但是存储了图像并且未存储文件名,前五个记录未插入如何纠正


My Error
My error page is run but image is stored and file name not stored first five record not insert how to correct

推荐答案

您正在将Byte []的myImagePathValue存储到varcharChar在数据库SystemUrl的列中,您需要将该值转换为字符串或字节,然后再将其存储到数据库中,因为您需要将该值与数据库表Column DataType相匹配,该列是SystemUrl varchar
your are storing myImagePathValue that is Byte[] to varcharChar Column of the Database SystemUrl you need to convert that value either into string or Byte before storing it into the Database because you need to match that value with your database table Column DataType which is SystemUrl varchar


在从数据库存储或检索数据库之前尝试此操作

将字节数组转换为字符串

Try this before storing or retrieving it from database

Converting a byte array to a string

byte[]bLine = new byte[...];
// Fill with data bLine = ... 
 System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); 
string str = enc.GetString(bLine);



将字符串转换为字节数组



Converting a string to a bytearray

string sStr = "whatever"
 System.Text.ASCIIEncoding  enc=new System.Text.ASCIIEncoding();
 byte []bArray = enc.GetBytes(sStr);


这篇关于图像插入和文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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