怎样将数据库中的文件(word文档)以"abc.doc"的名字命名并且保存在应用程序的同目录中 怎样将数据库中的文件(word文档)以"abc.doc"的名字命名并且保存在应用程序的同目录中 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string filePath=this.saveFileDialog1.FileName;SqlConnection myConnection=new SqlConnection();SqlCommand myCommand=new SqlCommand();myConnection.ConnectionString=ConnectionString; myConnection.Open();string sql="select FileContent from Sys_NoStructureDatas where Sys_ID="+id;myCommand.Connection=myConnection;myCommand.CommandType=CommandType.Text;myCommand.CommandText=sql;SqlDataReader myDataReader=myCommand.ExecuteReader();if(myDataReader.Read()){System.IO.FileInfo myFileInfo=new FileInfo(filePath);System.IO.FileStream myFileStream=myFileInfo.Open(System.IO.FileMode.OpenOrCreate);byte[] imgData=(byte[])myDataReader["FileContent"];foreach(byte a in imgData){myFileStream.WriteByte(a);}myFileStream.Close();myDataReader.Close();}myConnection.Close();MessageBox.Show("文件保存成功!",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Information);filePath是路径+文件名。 bhwhy(苏秦) :能不能加点中文说明 我的是access数据库里面保存文件名和文件数据 首先,你在数据库中存的也应当是word文档。否则读出时可能会错。可以像向北兄说的,把格式记下来。读出来的时候作判断生成什么格式的文件即可。上面那段就是从数据库中读文件,然后生成到一个指定的目录下啊。。关于文件读写的操作主要就是用System.IO.FileStream myFileStream,System.IO.FileInfo ,byte[] ,先读到byte[] 里,再写出来 Access里的不太了解。应当也一样吧。我写的是SQL里的,你在论坛中搜一下,肯定有介绍 谢过苏秦,我还是等access高手来吧 我的文件是在没有转换的情况下保存在数据库中的(就是说我在access数据库中打开表右点击OLE类型字段选择插入对象将文件保存在数据库中),我在网上看了些帖子觉得我的这种保存是以字节保存的文件,而不是二进制,请高手执教如何将这种文件读取出来保存在硬盘上,并且能打开 to 我在网上看了些帖子觉得我的这种保存是以字节保存的文件,而不是二进制,请高手执教如何将这种文件读取出来保存在硬盘上,并且能打开如果文件数据对应的是ole字段类型,肯定是用byte来进行保存的。只要反向操作即可。 网站检查发现死链和网页PR的问题 应用控制windows系统的问题 用timer计时器产生定时存储 关于Enterprise Library4 logging 中的FlatFileTraceListenerData的文件存储问题 求混淆器 关于进度条的问题!(相当的急!) 关于C#应用程序生成问题 有没有比较空闲的人 ----“中国铁路中国造 ”网络大签名 C#中如何重写CheckedListBox控件 请问哪里可以下载C#反向成rose的插件? DataGridView再次排序的思考 请教:如何在c#中对ACCESS数据库中的ole类型数据进行打开、存储等操作。
SqlCommand myCommand=new SqlCommand();myConnection.ConnectionString=ConnectionString;
myConnection.Open();string sql="select FileContent from Sys_NoStructureDatas where Sys_ID="+id;
myCommand.Connection=myConnection;
myCommand.CommandType=CommandType.Text;
myCommand.CommandText=sql;SqlDataReader myDataReader=myCommand.ExecuteReader();if(myDataReader.Read())
{
System.IO.FileInfo myFileInfo=new FileInfo(filePath);
System.IO.FileStream myFileStream=myFileInfo.Open(System.IO.FileMode.OpenOrCreate);byte[] imgData=(byte[])myDataReader["FileContent"];
foreach(byte a in imgData)
{
myFileStream.WriteByte(a);}myFileStream.Close();
myDataReader.Close();}myConnection.Close();
MessageBox.Show("文件保存成功!",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Information);filePath是路径+文件名。
上面那段就是从数据库中读文件,然后生成到一个指定的目录下啊。。关于文件读写的操作主要就是用System.IO.FileStream myFileStream,System.IO.FileInfo ,byte[] ,先读到byte[] 里,再写出来