读写数据库图象字段

从论坛上看到好多人在讨论这方面的问题,把代码整理出来,说不定回答问题的时候还能用上呢。

首先,是数据库的设计。我使用的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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值