C# 将图片保存到数据库

static void Main(string[] args)
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "server=192.168.30.7;database=AIS20170401213620;uid=sa;pwd=ABCabc123";
            //con.ConnectionString = "server=192.168.30.7;database=AIS20170720100743;uid=sa;pwd=ABCabc123";
            con.Open();
            //创建文件流,path参数是文件路径
            FileStream file = new FileStream(@"C:\Users\VULCAN\Desktop\火影桌面壁纸\Cg-4V1RSC-qIb5v4AAwP30B8ANkAAQsPAAtspsADA_3018.jpg", FileMode.Open);
            int streamLength = (int)file.Length;
            byte[] image = new byte[streamLength];//声明字节数组,保存图片文件
            file.Read(image, 0, streamLength); //把图片文件转换成字节数组保存
            file.Close();

            string sql = string.Format(" update t_BOS200000075  set fpicture=@image where fid='1000' ", image);
            //string sql = string.Format("update ");
            SqlCommand com = new SqlCommand(sql, con);
            com.Parameters.Add(new SqlParameter("image", SqlDbType.Binary, image.Length, ParameterDirection.Input, true, 0, 0, null, DataRowVersion.Default, image));

            SqlDataReader dr = com.ExecuteReader();
            dr.Close();
            con.Close();

        }

 

转载于:https://www.cnblogs.com/erph/p/7365640.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值