asp.net对图片的读写

25 篇文章 0 订阅
15 篇文章 0 订阅

 写图片c:/1.jpg到表cinfo中

private static void AddCinfo()
    {
        string strSql = "insert into cinfo (srvtitle,csttitle,introduction,logo) values

(@srvtitle,@csttitle,@introduction,@logo)";
        SqlParameter[] parms =
        {
            new SqlParameter("@srvtitle",SqlDbType.VarChar,30),
            new SqlParameter("@csttitle",SqlDbType.VarChar,30),
            new SqlParameter("@introduction",SqlDbType.NVarChar,500),
            new SqlParameter("@logo",SqlDbType.Image)
        };
        parms[0].Value = "旅业互动";
        parms[1].Value = "lyhd";
        parms[2].Value = "简介";

        string filePath = @"c:/1.jpg";
        FileStream fs = File.OpenRead(filePath);

        byte[] content = new byte[fs.Length];

        fs.Read(content, 0, content.Length);

        fs.Close();

        parms[3].Value = content;

        DBHelper.ExecuteNonQuery(CommandType.Text, strSql, parms);
    }

 

读取图片的页面 test.aspx

protected void Page_Load(object sender, EventArgs e)
    {
        string strSql = "select * from cinfo where id=1";
        SqlDataReader reader=DBHelper.ExecuteReader(CommandType.Text, strSql, null);
        if(reader.Read())
        {
            byte[] c=(byte[])reader["logo"];
            Response.BinaryWrite(c);
        }
    }

用来显示图片的页面 test2.aspx

<img src="test.aspx" />

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值