Sauver/Restaurer fichiers dans access

Résolu
cs_malara Messages postés 7 Date d'inscription dimanche 3 juillet 2005 Statut Membre Dernière intervention 11 décembre 2007 - 11 déc. 2007 à 03:14
TheSaib Messages postés 2367 Date d'inscription mardi 17 avril 2001 Statut Membre Dernière intervention 26 décembre 2007 - 11 déc. 2007 à 18:31
Bonjour à tous,

Quelqu'un a le bout de code permettant de sauvegarder un fichier en format binaire (xls,doc,...) dans un champ Ole de Access et en même temps pour le récupérer pour l'exécuter ??

Merci

1 réponse

TheSaib Messages postés 2367 Date d'inscription mardi 17 avril 2001 Statut Membre Dernière intervention 26 décembre 2007 23
11 déc. 2007 à 18:31
Comme çà ...

      //  only the attched file name not its path
        string c = System.IO.Path.GetFileName(curFileName);
        //  Read a bitmap contents in a stream
        FileStream fs = new FileStream(curFileName, FileMode.OpenOrCreate,
FileAccess.Read);
        byte[] rawData = new byte[fs.Length];
        fs.Read(rawData, 0, System.Convert.ToInt32(fs.Length));
        fs.Close();
        //  Construct a SQL string and a connection object
        OleDbConnection dbConn;
        OleDbCommand dbCmd;
        string applicationState = ((string)(Application["DBType"])).ToLower();
        string sConn = dbClass.Connect(applicationState);
        string sSQL;
        sSQL = "INSERT INTO table (champs) "
                + "VALUES (" 
                + "\'" + rawData + "\')";
        try
        {
                // write the visit log entry
                dbConn = new OleDbConnection(sConn);
                dbConn.Open();
                dbCmd = new OleDbCommand(sSQL, dbConn);
                dbCmd.ExecuteNonQuery();
                dbConn.Close(); 
                return;
        }
        catch (Exception excep)
        {
                Debug.WriteLine(excep.Message); 
                return;
        }

::|The S@ib|::
MVP C#.NET
3
Rejoignez-nous