重复将图像保存到数据库

时间:2019-06-20 10:23:34

标签: c# c#-4.0 linq-to-sql

保存/更新数据库中的图像只是我首先保存的图像的重复图像

这是针对C#Windows窗体的,我已经尝试将一些null放在变量上

这是我保存图像的代码

私有无效btnsave_Click(对象发送者,EventArgs e)


             if (pictureBox1.Image == null)
            {MessageBox.Show("Please insert a picture");}
            else
            {   byte[] img = null;
                FileStream fs = new FileStream(imgloc, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fs);
                img = br.ReadBytes((int)fs.Length);

                db.sp_saveofficials(Main.userid, img, txtfirstname.Text, textBox1.Text, txtlastname.Text, comboBox2.Text, 
                    dateTimePicker2.Value.Date, dateTimePicker1.Value.Date,login.username);
                dataGridView1.DataSource = db.sp_viewofficials();
                imgloc = null; }

我还猜想我的图片框代码中可能有问题

隐私无效pictureBox1_Click(对象发送者,EventArgs e)

OpenFileDialog open = new OpenFileDialog();
            PictureBox p = sender as PictureBox;
            if (p != null)
            {
                open.Filter = "(*.jpg;*.jpeg;*.bmp;*.png;*.gif;)|*.jpg; *.jpeg; *.bmp; *.png; *.png;";
                open.Title = "Select a picture";
                if (open.ShowDialog() == DialogResult.OK)
                {
                    imgloc = open.FileName.ToString() ;
                    p.ImageLocation = imgloc;
                }
            }  

我希望我可以将不同的图像保存在数据库中,

  

我尝试保存到数据库中的所有数据都具有与我第一次保存的图像相同的图像

这是我的db.sp_saveofficials代码供参考

        create proc sp_saveofficials
        @userid int,
        @pic varbinary(max),
        @fname varchar (50),
        @mname varchar (50),
        @lname varchar (50),
        @position varchar (50),
        @startterm  datetime, 
        @endterm  datetime,
        @addedby varchar (50)
        as
        insert into tblbarangayofficials values(@userid,@pic,@fname,@mname,@lname,@position,@startterm,@endterm,@addedby,GETDATE())

0 个答案:

没有答案