打印本文 打印本文 关闭窗口 关闭窗口
从SQL Server中读写大数据列。
作者:武汉SEO闵涛  文章来源:敏韬网  点击数3638  更新时间:2007/11/14 13:08:02  文章录入:mintao  责任编辑:mintao

/*
  Author:Wu Xiuxiang;
 Email:imessage@126.com

*/

public static void Main()
 
{
   
//写入大对象到SqlServer
   FileStream fs   = new FileStream("C:\\test.bmp",FileMode.OPen,FileAccess.Read);
   BinaryReader br 
= new BinaryReader(fs);

   SqlConnection conn 
= new SqlConnection("server=localhost;uid=sa;pwd=sa;database=northwind");

   
string cmdText = "UPDATE EMPLOYEES" +
         
"SET Photo=@image where EmployeeId=1";
   
   SqlCommand cmd 
= new SqlCommand(cmdText,conn);
   cmd.Parameters.Add(
"@image",SqlDbType.Image);

   cmd.Parameters[
"@image"].Value = br.ReadBytes((int)br.BaseStream.Length);

   conn.Open();
   
int i=cmd.ExecuteNoQuery();


   
//从SQL Server中读取大对象
   string cmdtext = "SELECT employeeid,photo" +
          
" from employees where employeeid = 1";
   
 
  SqlCommand cmd2 
= new SqlCommand(cmdtext,conn);

  FileStream rfs

[1] [2] [3]  下一页

打印本文 打印本文 关闭窗口 关闭窗口