这是保存到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类型
保存:
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类型
http://www.chinaaspx.com/article/go.asp?id=267&typeid=2
http://www.chinaaspx.com/article/go.asp?id=268&typeid=2
{
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;
}
}