private int WriteToDB(string strName, string strType, ref byte[] Buffer)
{
int nFileID = 0; // Create connection
OleDbConnection dbConn = new OleDbConnection(GetConnectionString()); // Create Adapter
OleDbDataAdapter dbAdapt = new OleDbDataAdapter("SELECT * FROM tblFile", dbConn);
// We need this to get an ID back from the database
dbAdapt.MissingSchemaAction = MissingSchemaAction.AddWithKey;
// Create and initialize CommandBuilder
OleDbCommandBuilder dbCB = new OleDbCommandBuilder(dbAdapt); // Open Connection
dbConn.Open();
// New DataSet
DataSet dbSet = new DataSet();
// Populate DataSet with data
dbAdapt.Fill(dbSet, "tblFile"); // Get reference to our table
DataTable dbTable = dbSet.Tables["tblFile"]; // Create new row
DataRow dbRow = dbTable.NewRow(); // Store data in the row
dbRow["FileName"] = strName;
dbRow["FileSize"] = Buffer.Length;
dbRow["ContentType"] = strType;
dbRow["FileData"] = Buffer; // Add row back to table
dbTable.Rows.Add(dbRow); // Update data source
dbAdapt.Update(dbSet, "tblFile"); // Get newFileID
if( !dbRow.IsNull("FileID") )
nFileID = (int)dbRow["FileID"];
// Close connection
dbConn.Close(); // Return FileID
return nFileID;
}
{
int nFileID = 0; // Create connection
OleDbConnection dbConn = new OleDbConnection(GetConnectionString()); // Create Adapter
OleDbDataAdapter dbAdapt = new OleDbDataAdapter("SELECT * FROM tblFile", dbConn);
// We need this to get an ID back from the database
dbAdapt.MissingSchemaAction = MissingSchemaAction.AddWithKey;
// Create and initialize CommandBuilder
OleDbCommandBuilder dbCB = new OleDbCommandBuilder(dbAdapt); // Open Connection
dbConn.Open();
// New DataSet
DataSet dbSet = new DataSet();
// Populate DataSet with data
dbAdapt.Fill(dbSet, "tblFile"); // Get reference to our table
DataTable dbTable = dbSet.Tables["tblFile"]; // Create new row
DataRow dbRow = dbTable.NewRow(); // Store data in the row
dbRow["FileName"] = strName;
dbRow["FileSize"] = Buffer.Length;
dbRow["ContentType"] = strType;
dbRow["FileData"] = Buffer; // Add row back to table
dbTable.Rows.Add(dbRow); // Update data source
dbAdapt.Update(dbSet, "tblFile"); // Get newFileID
if( !dbRow.IsNull("FileID") )
nFileID = (int)dbRow["FileID"];
// Close connection
dbConn.Close(); // Return FileID
return nFileID;
}
解决方案 »
- |zyciis| C#4.0传说中的新特性:安全的null延迟赋值操作符,但真实出来没有,那我们如何来实现这个功能呢?有点变态 谢谢
- asp.net(c#)如何引用weboffice插件
- 如何把前台JS取的值传到后台中并写入表?AJAX?
- SQL Server问题
- 有没有人研究在线考试系统
- 庆祝ZForums升级到4.0,优秀的.NET论坛。
- .Net服务器端控件Table1的使用???
- 一个ASP.NET的经验问题,散分讨论,有经验的谈谈,谢谢!
- 关于NameSpace问题!
- 在datagrid里,换页后,又回到第一页时,由于再次绑定数据所以原来选中的效果丢失,我该如何保持选中呢?
- SqlConnection.open()时为什么出错?
- 请问Transfer是怎么用法?
// Create connection
OleDbConnection dbConn = new OleDbConnection(GetConnectionString());// Create Adapter
OleDbDataAdapter dbAdapt = new OleDbDataAdapter("SELECT * FROM tblFile", dbConn);
// We need this to get an ID back from the database
dbAdapt.MissingSchemaAction = MissingSchemaAction.AddWithKey;
// Create and initialize CommandBuilder
OleDbCommandBuilder dbCB = new OleDbCommandBuilder(dbAdapt);
ref byte[] buffer
的文件体的值,我如何赋给?文件一般都在客户端
在ASP.NET中存取图片到数据库的示例
private void Page_Load(object sender, System.EventArgs e)
{
string DangAnNoparam=Request.Params["DangAnNo"];
if (DangAnNoparam==null)
{
oaDA_DB DownLoadDA = new oaDA_DB();
SqlDataReader DangAnFile = DownLoadDA.DownloadDangAnFile(DangAnNoparam);//qer test if (DangAnFile.Read())
{
Response.ContentType = DangAnFile.GetString(11);//设定输出文件类型
Byte[] filebuffer = new Byte[DangAnFile.GetInt32(12)];
DangAnFile.GetBytes(9,0,filebuffer,0,DangAnFile.GetInt32(12));
Response.OutputStream.Write(filebuffer, 0, DangAnFile.GetInt32(12)); //输出文件二进制数制
Response.End();
}
else
{
this.Response.Write("此档案没有相关的附件!");
} }
else
{
this.Response.Write("没有提供档案编号,无法下载附件!");
}
// 在此处放置用户代码以初始化页面
}--------------------------------------------------------------------
问题是这样的,我在SQL库中保存了原用户上载时的文件名,下载给客户时,我仍然想用原用户的文件名,不知用什么方法设置?
Response.AddHeader("Content-Disposition", "attachment; filename=" + 文件名);
Response.ContentType = DangAnFile.GetString(11);//设定输出文件类型
.......