Aspose.Words.Examples.CSharp.Loading_Saving.LoadAndSaveDocToDatabase.StoreToDatabase C# (CSharp) Метод

StoreToDatabase() публичный статический Метод

public static StoreToDatabase ( Document doc, System.Data.OleDb.OleDbConnection mConnection ) : void
doc Document
mConnection System.Data.OleDb.OleDbConnection
Результат void
        public static void StoreToDatabase(Document doc, OleDbConnection mConnection)
        {
            // Save the document to a MemoryStream object.
            MemoryStream stream = new MemoryStream();
            doc.Save(stream, SaveFormat.Doc);

            // Get the filename from the document.
            string fileName = Path.GetFileName(doc.OriginalFileName);

            // Create the SQL command.
            string commandString = "INSERT INTO Documents (FileName, FileContent) VALUES('" + fileName + "', @Doc)";
            OleDbCommand command = new OleDbCommand(commandString, mConnection);

            // Add the @Doc parameter.
            command.Parameters.AddWithValue("Doc", stream.ToArray());

            // Write the document to the database.
            command.ExecuteNonQuery(); 
        }
        // ExEnd:StoreToDatabase