图片保存到数据及从数据库读出(winform,c# 和vb.net)

这是一个使用C#和VB.NET在Winform应用程序中实现图片保存到数据库以及从数据库读出的示例。程序包含打开文件对话框选择图片,将图片内容转化为字节流插入数据库,以及根据名称从数据库中读取并显示图片的功能。
摘要由CSDN通过智能技术生成

C#
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Windows.Forms;


namespace regedit
{
 /// <summary>
 /// Picture 的摘要描述。
 /// </summary>
 public class Picture : System.Windows.Forms.Form
 {
  private System.Windows.Forms.OpenFileDialog openFileDlg;
  private System.Windows.Forms.Label label1;
  private System.Windows.Forms.Button btnBrowse;
  private System.Windows.Forms.TextBox txtfile;
  private System.Windows.Forms.Button btnInsert;
  private System.Windows.Forms.TextBox txtname;
  private System.Windows.Forms.Button button1;
  private System.Windows.Forms.PictureBox pictureBox1;
  
  /// <summary>
  /// 設計工具所需的變數。
  /// </summary>
  private System.ComponentModel.Container components = null;
  SqlConnection conn=new SqlConnection("Data Source=localhost; Integrated Security=SSPI;Initial Catalog=mis");
  public Picture()
  {
   //
   // Windows Form 設計工具支援的必要項
   //
   InitializeComponent();

   //
   // TODO: 在 InitializeComponent 呼叫之後加入任何建構函式程式碼
   //
  }

  /// <summary>
  /// 清除任何使用中的資源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if(components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows Form 設計工具產生的程式碼
  /// <summary>
  /// 此為設計工具支援所必須的方法 - 請勿使用程式碼編輯器修改
  /// 這個方法的內容。
  /// </summary>
  private void InitializeComponent()
  {
   this.openFileDlg = new System.Windows.Forms.OpenFileDialog();
   this.label1 = new System.Windows.Forms.Label();
   this.txtfile = new System.Windows.Forms.TextBox();
   this.btnBrowse = new System.Windows.Forms.Button();
   this.btnInsert = new System.Windows.Forms.Button();
   this.txtname = new System.Windows.Forms.TextBox();
   this.button1 = new System.Windows.Forms.Button();
   this.pictureBox1 = new System.Windows.Forms.PictureBox();
   this.SuspendLayout();
   //
   // label1
   //
   this.label1.Location = new System.Drawing.Point(16, 16);
   this.label1.Name = "label1";
   this.label1.Size = new System.Drawing.Size(72, 23);
   this.label1.TabIndex = 0;
   this.label1.Text = "ImageName";
   //
   // txtfile
   //
   this.txtfile.Location = new System.Drawing.Point(88, 16);
   this.txtfile.Name = "txtfile";
   this.txtfile.Size = new System.Drawing.Size(384, 22);
   this.txtfile.TabIndex = 1;
   this.txtfile.Text = "";
   //
   // btnBrowse
   //
   this.btnBrowse.Location = new System.Drawing.Point(24, 48);
   this.btnBrowse.Name = "btnBrowse";
   this.btnBrowse.TabIndex = 2;
   this.btnBrowse.Text = "Browse";
   this.btnBrowse.Click += new System.EventHandler(this.btnBrowse_Click);
   //
   // btnInsert
   //
   this.btnInsert.Location = new System.Drawing.Point(112, 48);
   this.btnInsert.Name = "btnInsert";
   this.btnInsert.TabIndex = 3;
   this.btnInsert.Text = "Insert";
   this.btnInsert.Click += new System.EventHandler(this.btnInsert_Click);
   //
   // txtname
   //
   this.txtname.Location = new System.Draw

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值