
用
文件流的方式,把从文件中读出的数据转换成二进制,从数据库中读出就是反方向的:** void button1_Click(object sender, EventArgs e){byte[] bufferbuffer = File.ReadAllBytes(\"readme.doc\")//读取文件内容//创建连接SqlConnection connect = new SqlConnection(@\"Integrated Security=SSPIPersist Security Info=FalseInitial Catalog=BSPlatform2008Data Source=.\\SqlExpress\")SqlCommand cmd = connect.CreateCommand()cmd.CommandText = \"INSERT INTO Tmp (FileContent) VALUES (@FileContent)\"//FileContent字段是Image类型cmd.Parameters.Add(\"@FileContent\", SqlDbType.Image)cmd.Parameters[\"@FileContent\"].Value = buffer//接受byte[]类型的值connect.Open()cmd.ExecuteNonQuery()connect.Close()} 查看更多答案>>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"] = strNamedbRow["FileSize"] = Buffer.LengthdbRow["ContentType"] = strTypedbRow["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} 写入库。 private void ShowTheFile(int FileID) { // Define SQL select statement string SQL = "SELECT FileSize, FileData, ContentType FROM tblFile WHERE FileID = " + FileID.ToString()// Create Connection object OleDbConnection dbConn = new OleDbConnection(GetConnectionString())// Create Command Object OleDbCommand dbComm = new OleDbCommand(SQL, dbConn)// Open Connection dbConn.Open()// Execute command and receive DataReader OleDbDataRea用streamreader直接读成byte[]
然后用ado什么的都好了,存到access的data结构里
至于这个读取再显示到另一word中是什么意思呢?
是调用word程序打开这个word呢?如果这样,就要把access读到的byte【】用writer写到temp.doc,然后调用shellexcute执行 temp.doc就ok了
至于shellexcute从系统dll中调用要使用下面代码
[DllImport("shell32.dll ")]
public static extern int ShellExecute(IntPtr hwnd, StringBuilder lpszOp,
StringBuilder lpszFile, StringBuilder lpszParams, StringBuilder lpszDir, int FsShowCmd)
如果不保存word的话,你还是自己设计个格式,或者把文字存文字,图片存图片,。。。
评论列表(0条)