当前位置:编程学习 > C#/ASP.NET >>

从SQL Server中读写大数据列

答案: 

/*
  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";
   
sql server 与 excel 互导以及在asp.net中从DataTable导出到excel
下一个:在DataGrid中,使鼠标到达的行和列显示不同的颜色

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,