北大青鸟佳音旗舰

C#实现文本文件存入数据库并取出

点击数: 更新时间:2010-05-21 15:55:24
 

byte[]text= File.ReadAllBytes(this.openFileDialog1.FileName);

  SqlConnection con = new SqlConnection("data source=.;initial catalog=demo;user id=sa;pwd=");

  SqlCommand comm = new SqlCommand("Insert Into c (s) Values (@Image)", con);

  comm.Parameters.Add(new SqlParameter("@Image", text));

  con.Open();

  comm.ExecuteNonQuery();

  con.Close();

  string sql = "select s from c";

  comm = new SqlCommand(sql, con);

  con.Open();

  byte[] s = (byte[])comm.ExecuteScalar();

  this.textBox1.Text = System.Text.Encoding.Default.GetString(s, 0, s.Length);

 


            

上一篇:15个JavaScript Web UI库[ 05-21 ]下一篇:C#实现自动锁屏+关屏[ 05-21 ]
相关信息
没有相关内容
©Copyright2004 - 2011 , All Rights Reserved
地址:北京西城区北礼士路100号( 阜成门华联商厦西门北侧北走50米)100037北大青鸟地址
京ICP备06064589号
51.la