怎样word文档以二进制流的形式存入数据库
1个回答
展开全部
protected void Button1_Click(object sender, EventArgs e)
{
//FileInfo thefile = new FileInfo(@"D:\立项依据.doc");
FileStream fsDoc = File.OpenRead(@"D:\立项依据.doc");
DateTime dtnow = DateTime.Now;
string filename = dtnow.ToString("yyyyMMdd")+".doc";
byte[] buffer=new byte[fsDoc.Length];
fsDoc.Read(buffer,0,(int)fsDoc.Length);
conn.Open();
string sqlCmd = @"Insert into MyUploadTable(filename,filesize,filedata,ProjectID,IsAuditActivePage)
Values(@filename,@filesize,@filedata,@ProjectID,1)";
SqlCommand Cmd = new SqlCommand(sqlCmd,conn);
Cmd.Parameters.Add("@filename",SqlDbType.VarChar).Value=filename;
Cmd.Parameters.Add("@filesize",SqlDbType.BigInt).Value=fsDoc.Length;
Cmd.Parameters.Add("@filedata",SqlDbType.Image).Value=buffer;
Cmd.Parameters.Add("@ProjectID",SqlDbType.Int).Value=2;
Cmd.ExecuteNonQuery();
fsDoc.Close();
conn.Close();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |