惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
L
LangChain Blog
U
Unit 42
Apple Machine Learning Research
Apple Machine Learning Research
The Cloudflare Blog
Martin Fowler
Martin Fowler
T
Tenable Blog
IT之家
IT之家
H
Help Net Security
阮一峰的网络日志
阮一峰的网络日志
Forbes - Security
Forbes - Security
N
Netflix TechBlog - Medium
The Hacker News
The Hacker News
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Tailwind CSS Blog
美团技术团队
NISL@THU
NISL@THU
T
Threatpost
GbyAI
GbyAI
T
Threat Research - Cisco Blogs
I
InfoQ
Jina AI
Jina AI
Microsoft Azure Blog
Microsoft Azure Blog
人人都是产品经理
人人都是产品经理
C
Check Point Blog
V
Vulnerabilities – Threatpost
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Spread Privacy
Spread Privacy
S
Securelist
大猫的无限游戏
大猫的无限游戏
P
Privacy & Cybersecurity Law Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
爱范儿
爱范儿
小众软件
小众软件
C
Cybersecurity and Infrastructure Security Agency CISA
Cisco Talos Blog
Cisco Talos Blog
Engineering at Meta
Engineering at Meta
S
Security Affairs
S
Secure Thoughts
T
Troy Hunt's Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
aimingoo的专栏
aimingoo的专栏
博客园 - 司徒正美
PCI Perspectives
PCI Perspectives
C
Cisco Blogs
MongoDB | Blog
MongoDB | Blog
Vercel News
Vercel News
月光博客
月光博客
Recorded Future
Recorded Future

博客园 - 老男孩玩编程

PHP双冒号::的用法 php中的反引号 十四条令PHP初学者头疼问题大总结 免费开源微博程序大全——免费开源微博对比解析 JavaScript窗口与提示大全 大型网站,我建议要考虑的问题: 制作精美圆角表格两种方法 关于GridView中自定义分页、单选、多选的简单应用 SQL精华 ASP.NET编程中的十大技巧 SQL SERVER临时表的使用 有效编写软件的75条建议 IT从业人员必看的10个论坛 程序员每天该做的事 动态生成button并关联其onclick事件 在ASP.NET 中实现单点登录 简单的数据连接方法 ASP.NET程序中常用的三十三种代码 SQL语法全集
使用C#从数据库读取图像二进制流的代码
老男孩玩编程 · 2006-12-08 · via 博客园 - 老男孩玩编程

工作需要,要判断一个老的数据库中image存放的数据类型,写了一段代码,放在这里供大家参考。除数据库部分需要大家修改一下以外,其它全部调试正常。里面有意思的是省却了connection的close方法,而用了另一种方式取代,希望大家能注意一下。
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace image
{
 public class Form1 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.Button button1;
  private System.Windows.Forms.ListBox listBox1;
  private System.ComponentModel.Container components = null;

  public Form1()
  {

   InitializeComponent();

  }

  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows 窗体设计器生成的代码

  private void InitializeComponent()
  {
   this.button1 = new System.Windows.Forms.Button();
   this.listBox1 = new System.Windows.Forms.ListBox();
   this.SuspendLayout();
 
   this.button1.Location = new System.Drawing.Point(104, 216);
   this.button1.Name = "button1";
   this.button1.TabIndex = 0;
   this.button1.Text = "button1";
   this.button1.Click += new System.EventHandler(this.button1_Click);
  
   this.listBox1.ItemHeight = 12;
   this.listBox1.Location = new System.Drawing.Point(0, 0);
   this.listBox1.Name = "listBox1";
   this.listBox1.Size = new System.Drawing.Size(200, 172);
   this.listBox1.TabIndex = 1;
 
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(292, 273);
   this.Controls.Add(this.listBox1);
   this.Controls.Add(this.button1);
   this.Name = "Form1";
   this.Text = "Image";
   this.Load += new System.EventHandler(this.Form1_Load);
   this.ResumeLayout(false);

  }
  #endregion

 
  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }

  private void Form1_Load(object sender, System.EventArgs e)
  {
  
  }

  private void button1_Click(object sender, System.EventArgs e)
  {
   string myConnectionString="workstation id=820SERVER;packet size=4096;integrated security=SSPI;data source=820SERVER;persist security info=False;initial catalog=images";
   string mySelectQuery="SELECT * FROM VBADGE";
   CreateMySqlDataReader(mySelectQuery,myConnectionString);
  }

  public void CreateMySqlDataReader(string mySelectQuery,string myConnectionString)
  {
   byte[] tmp;
   SqlConnection myConnection = new SqlConnection(myConnectionString);
   SqlCommand myCommand = new SqlCommand(mySelectQuery, myConnection);
   myConnection.Open();
   SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
   myReader.Read();
   tmp=(byte[])myReader[0];
   FileStream fs = new FileStream("tmp.tmp",FileMode.CreateNew);
   BinaryWriter w = new BinaryWriter(fs);
   w.Write(tmp);
   w.Close();   
   myReader.Close();
  }

 }
}