将多个图像从两个picbox保存到sql [英] save multi image from two picbox to sql

查看:95
本文介绍了将多个图像从两个picbox保存到sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好大家:)



如何用一个filestream命令将两个pictureBox中的两个图像保存到sql中?我想我必须制作但我不知道怎么会这样,如果你可以请给手

这是我的代码我重复了一些线!



hello everyone :)

how i can save two image from two pictureBox into sql with one filestream command? i think i have to makearry but im not sure how so if you could please give hand
and this is my code i have repeated some line !

private void button2_Click(object sender, EventArgs e)
        {
            byte[] bt = null;

      FileStream fs = new FileStream(pictureBox1.ImageLocation, FileMode.Open, FileAccess.Read);// this is for first image selected in picbox1
            FileStream fs2 = new FileStream(pictureBox2.ImageLocation, FileMode.Open, FileAccess.Read);// here i repeated the upper line 
            
            BinaryReader bnr = new BinaryReader(fs);
            BinaryReader bnr1 = new BinaryReader(fs2);//here
            bt = bnr1.ReadBytes((int)fs2.Length);// again 
            bt = bnr.ReadBytes((int)fs.Length);

 SqlCommand cmd = new SqlCommand("insert into tbldesgin(dsname,fside,bcside)values(@dsname,@fside,@bcside)", cn);
            cmd.Parameters.Add(new SqlParameter("@fside", bt));
            cmd.Parameters.Add(new SqlParameter("@bcside", bt));
            
            cmd.Parameters.AddWithValue("@dsname", textBox1.Text);
            
            cn.Open();
            cmd.ExecuteNonQuery();
            cn.Close();
            MessageBox.Show("data has been sent");
            pictureBox1.Image = null;

        }

推荐答案

非常简单,因为你有图像。忽略该位置,并使用PictureBox.Image属性中的当前数据。

请参阅此处:为什么我得到参数无效。我从数据库中读取图像时出现异常? [ ^ ] - 它显示了如何将图像保存到SQL中 - 您所要做的就是加倍代码,然后插入两个字节数组而不是一个。
Pretty simple, since you have the images. Ignore the location, and use the current data in the PictureBox.Image property.
See here: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^] - it shows how to save an Image into SQL - all you have to do is "double up" the code, and insert two byte arrays instead of one.


这篇关于将多个图像从两个picbox保存到sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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