日期:2012-06-05 浏览次数:20541 次
/*
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();