C# 数据库存放图片代码
来源:互联网 发布:电子狗升级软件下载 编辑:程序博客网 时间:2024/05/22 09:49
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.SqlClient;
using System.IO;
namespace ImageOperation2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnObserve_Click(object sender, EventArgs e)
{
string constr = "Data Source=PC-200911031859;Initial Catalog=Image2;Integrated Security=True";
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
OpenFileDialog f = new OpenFileDialog();
DialogResult re = f.ShowDialog();
if (re == DialogResult.OK)
{
string s=f.FileName;
FileStream fs = new FileStream(f.FileName, FileMode.Open, FileAccess.Read);
BinaryReader reder = new BinaryReader(fs);
byte[] bb = new byte[fs.Length];
bb = reder.ReadBytes(Convert.ToInt32(fs.Length));
SqlCommand com = new SqlCommand("insert into picture2 values(@ImageList)", con);
com.Parameters.Add("ImageList", SqlDbType.Image);
com.Parameters["ImageList"].Value = bb;
com.ExecuteNonQuery();
//string str="";
//string sql = "insert into picture2(piccontent) values(" + bb+ ")";
//cmd.CommandText = sql;
//cmd.ExecuteNonQuery();
picBoxShow.Image = Image.FromFile(s);
}
con.Close();
}
private void btnSearch_Click(object sender, EventArgs e)
{
string s = "";
string constr = "Data Source=PC-200911031859;Initial Catalog=Image2;Integrated Security=True";
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
string sql = "select piccontent from picture2 where picid=7";
cmd.CommandText = sql;
SqlDataReader reader = cmd.ExecuteReader();
DataSet dd = new DataSet();
while (reader.Read())
{
s = reader.GetValue(0).ToString();
byte[] bb = (byte[])(reader.GetValue(0));
//byte[] bb =new byte[s.Length];
//for (int i = 0; i < s.Length; i++)
//{
// bb[i] = Convert.ToByte(s[i]);
//}
MemoryStream me=new MemoryStream(bb);
Bitmap map = new Bitmap(me);
picBoxShow.Image = map;
me.Close();
}
reader.Close();
}
}
}
- C# 数据库存放图片代码
- c# 图片二进制存放
- 数据库存放图片及视频
- c#将图片存放在dll中
- 将图片存放在数据库中的方法
- 关于mysql数据库图片存放的问题
- 安卓xml存放图片,在代码中取出
- 织梦dedecms图片按月存放怎么实现?代码分享
- 怎么样把图片存放到SQL SERVER 数据库中?
- Java实现向数据库中存放和读取图片
- iOS中如何把图片存放入SQLite数据库
- springmvc图片的本地上传和存放数据库
- Java实现向数据库中存放和读取图片
- 图片不存放文件夹,直接存在数据库中,
- C#数据库存取图片
- C# 读写数据库图片
- c#读写数据库图片
- C#图片存入数据库
- 指针二三事
- 用Socket实现的简单客户端和服务端程序(二)
- Ubuntu 9.10 下 QT 4.5.3 与 QtEmbeded 4.5.3 安装
- free -m
- SQL Server 2005 中的分区表和索引
- C# 数据库存放图片代码
- 交换两个数(不引入第三个变量)
- JDK5.0 Annotation 入门介绍
- 子类函数使用父类类型做为参数时,调用该参数的protected变量问题
- C++内联函数(Inline)介绍-ZT
- 忆龙2009:动态LACP
- 根据日期的前一天后一天的改变查询数据
- SQL Server 表分区(partitioned table/Data Partitioning)
- [经验总结]Ubuntu 9.10初用手记