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;
using System.Text;
namespace Image_.Net
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.TextBox txtImage;
private SqlConnection con;
private SqlParameter par;
private System.Windows.Forms.Button btnimage;
private System.Windows.Forms.TextBox txtOut;
private System.Windows.Forms.PictureBox pictureBox1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null) 
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.txtImage = new System.Windows.Forms.TextBox();
this.btnimage = new System.Windows.Forms.Button();
this.txtOut = new System.Windows.Forms.TextBox();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
// 
// button1
// 
this.button1.Location = new System.Drawing.Point(8, 32);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(88, 24);
this.button1.TabIndex = 0;
this.button1.Text = "上传图片";
this.button1.Click += new System.EventHandler(this.button1_Click);
// 
// txtImage
// 
this.txtImage.Location = new System.Drawing.Point(128, 32);
this.txtImage.Name = "txtImage";
this.txtImage.Size = new System.Drawing.Size(136, 21);
this.txtImage.TabIndex = 1;
this.txtImage.Text = "";
// 
// btnimage
// 
this.btnimage.Location = new System.Drawing.Point(8, 88);
this.btnimage.Name = "btnimage";
this.btnimage.Size = new System.Drawing.Size(88, 23);
this.btnimage.TabIndex = 2;
this.btnimage.Text = "取出图片";
// 
// txtOut
// 
this.txtOut.Location = new System.Drawing.Point(128, 88);
this.txtOut.Name = "txtOut";
this.txtOut.Size = new System.Drawing.Size(136, 21);
this.txtOut.TabIndex = 3;
this.txtOut.Text = "";
// 
// pictureBox1
// 
this.pictureBox1.Location = new System.Drawing.Point(8, 128);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(272, 120);
this.pictureBox1.TabIndex = 4;
this.pictureBox1.TabStop = false;
// 
// Form1
// 
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.txtOut);
this.Controls.Add(this.btnimage);
this.Controls.Add(this.txtImage);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// </summary>
[STAThread]
static void Main() 
{
Application.Run(new Form1());
}
//存放图片到sqlserver数据库
private void button1_Click(object sender, System.EventArgs e)
{
try
{
this.openFileDialog1.ShowDialog();//打开窗口选择图片
con=new SqlConnection("server=.;database=Info;uid=sa;pwd=;");//连接数据库
con.Open();//打开
SqlCommand cmd=new SqlCommand("insert into images values(@iname)",con);//插入图片

par=cmd.Parameters.Add("@iname",SqlDbType.Image);
FileStream fs=File.OpenRead(this.openFileDialog1.FileName.ToString());
byte[] img=new byte[fs.Length];
fs.Read(img,0,img.Length);
par.Value=img;
cmd.ExecuteNonQuery();//执行语句
MessageBox.Show("图片存放成功");
}
catch(System.Exception ex)
{
MessageBox.Show("dd"+ex);
}
}
}
}请大家看一下这个问题...?