//上传
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "*jpg|*.JPG|*.gif|*.GIF|*.bmp|*.BMP|*.png|*.PNG";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string fullpath = openFileDialog1.FileName;//文件路径
this.txtfile.Text = fullpath;
try
{
FileStream fs = new FileStream(fullpath, FileMode.Open);
byte[] imagebytes = new byte[fs.Length];
BinaryReader br = new BinaryReader(fs);
imagebytes = br.ReadBytes(Convert.ToInt32(fs.Length));
//打开数据库
SqlConnection con = new SqlConnection("server=(local); database =wanglei ; integrated security=true");
con.Open();
SqlCommand com = new SqlCommand("insert into imginfo values(@imgname )", con);
&

这篇博客展示了如何在WinForm应用中实现图片的数据库读取与存入。通过`button1_Click`事件处理函数,用户可以选择图片并将其转换为字节数组存储到数据库。`bind`方法用于填充数据网格视图,展示所有图片信息。`button2_Click`事件读取数据库中的第一条图片数据,并在pictureBox中显示。此外,还提供了删除图片的功能,当用户点击dataGridView中的行,`button3_Click`会删除对应的图片记录。
最低0.47元/天 解锁文章
788

被折叠的 条评论
为什么被折叠?



