使用C#语言如何将图片或doc文件保存到数据库,如何读出?

lucky420 2003-08-21 06:38:58
使用C#语言如何将图片和word文档保存到oracle数据库,如何读出?
...全文
99 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lucky420 2003-08-25
  • 打赏
  • 举报
回复
我想把doc文档保存到oracle数据库中,使用的是BLOB类型字段,想用c#的OleDb数据提供者读写,如何实现?
wanghuixue 2003-08-22
  • 打赏
  • 举报
回复
up
gOODiDEA 2003-08-22
  • 打赏
  • 举报
回复
直接从库中读出数据为byte[] xxx然后调用下面的方法

DownloadStream( this, xxx, "D:\\sds.doc" );

public bool DownloadStream( System.Web.UI.Page refPage, byte[] FileData, string _FileName )
{
try
{
string MyContentType = "";
switch ( _FileName.Substring( _FileName.LastIndexOf( "." ), 4 ) )
{
case ".xls":
MyContentType = "application/vnd.ms-excel";
break;
case ".doc":
MyContentType = "application/msword";
break;
default:
MyContentType = "application/zip";
break;
}
refPage.Response.Write( "MyContentType" );
refPage.Response.Clear();
refPage.Response.AddHeader( "Content-Type", MyContentType );
string FileName = System.Web.HttpUtility.UrlEncode( System.Text.Encoding.UTF8.GetBytes( _FileName ) );
refPage.Response.AddHeader("Content-Disposition", "inline;filename="+ System.Convert.ToChar(34) + FileName + System.Convert.ToChar(34) );
refPage.Response.AddHeader("Content-Length", FileData.Length.ToString() );
refPage.Response.BinaryWrite( FileData );
refPage.Response.End();
return true;
}
catch
{
return false;
}
}
dahuzizyd 2003-08-21
  • 打赏
  • 举报
回复
看这里:
http://www.chinaaspx.com/article/go.asp?id=267&typeid=2
http://www.chinaaspx.com/article/go.asp?id=268&typeid=2
chenyl0925 2003-08-21
  • 打赏
  • 举报
回复
这是保存到sql2000的代码,希望对你有借鉴作用
保存:
Stream imgDataStream = this.fileLoad.PostedFile.InputStream;
int imgDataLenth = this.fileLoad.PostedFile.ContentLength;
byte[] imgDataList = new byte[imgDataLenth];
imgDataStream.Read(imgDataList,0,imgDataLenth);
string updateSql = "Select * from unformatdata where ID = " + Session["sID"].ToString();
//创建sqlCommand对象
string conString = "server = (local);database = pratice;user id = sa; pwd = ";
SqlConnection myConnection = new SqlConnection(conString);
SqlCommand myCommand = new SqlCommand(updateSql,myConnection);
myCommand.Connection.Open();
try
{
SqlDataAdapter MyAdapter=new SqlDataAdapter();
SqlCommandBuilder Var_SqlCB;
MyAdapter.SelectCommand=myCommand;
Var_SqlCB = new SqlCommandBuilder(MyAdapter);
DataSet myDataSet=new DataSet();
MyAdapter.Fill(myDataSet,"myTable");
myDataSet.Tables["myTable"].Rows[0]["Unfordata"] = (byte[])imgDataList;
}
catch(Exception ex)
{
System.Console.WriteLine(ex.Message.ToString());
}
myCommand.Connection.Close();
读出类似。另外,图片和word在数据库中的保存类型是image类型

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧