从论坛上看到好多人在讨论这方面的问题,把代码整理出来,说不定回答问题的时候还能用上呢。
首先,是数据库的设计。我使用的Access数据库。定义一个数据表photo.mdb,定义两个字段photoID和photo ,其中photoID为主键,字段类型为“文本”,photoID的字段类型为“OLE对象”。(注意:如果采用SQL数据库photo的字段类型为“image “。
以字节形式读写数据库图象字段:
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
using
System.Data.OleDb;
using
System.IO;
namespace
WindowsApplication2
...
{
public partial class Form1 : Form
...{
public OleDbConnection dbconn = new OleDbConnection();
public OleDbCommand comm = new OleDbCommand();
public Form1()
...{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
...{
this.OpenConn();
this.pictureBox1.Image = null;
Image im;
this.getPhoto("0000", out im);
this.pictureBox1.Image = im;
}
/**//// <summary>
/// 从数据库中读取图象
/// </summary>
/// <param name="pid"></param>

本文介绍如何处理Access数据库中的图像字段,包括字段类型设置(OLE对象或image),并提供以字节形式读写图像数据的方案。
最低0.47元/天 解锁文章
1万+

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



