将图片插入ms access2003 [英] insert image into ms access2003

查看:86
本文介绍了将图片插入ms access2003的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Visual Studio2008中开发我的项目,并且我具有将图像浏览到图片框并将其保存到access2003数据库中的形式.请告诉我完成此过程的完整过程.

i am developing my project in visual studio2008 & i have form where i am browsing image into picturebox and save it into access2003 database.plz tell me the complete procedure how to accomplish this.

推荐答案

在数据库中创建一个字段,使其成为OleObject类型,并将其命名为myImage
然后:
Create a field in your database, make it OleObject type, call it myImage
Then:
using (OdbcConnection con = new OdbcConnection(connectionString))
    {
    using (OdbcCommand com = new OdbcCommand("INSERT INTO myTable (myImage) VALUES (@IM)", con))
        {
        MemoryStream ms = new MemoryStream();
        MyPictureBox.Image.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp);
        byte[] imageData = ms.ToArray();
        com.Parameters.AddWithValue("@IM", imageData);
        com.ExecuteNonQuery();
        }
    }


这篇关于将图片插入ms access2003的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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