3

http://filehelpers.sourceforge.net/example_sqlstorage_extract.html

The example above connects to SQl server.

My requirement is to connect to Oracle DB.I found no class in filehelpers which i can use to connect to oracle DB. Please help if you have any ideas. Thanks a lot.

shamp00
  • 11,106
  • 4
  • 38
  • 81
user1046415
  • 779
  • 4
  • 23
  • 43

1 Answers1

1

You can use the GenericDatabaseStorage<T> class which takes any ADO.NET IDBConnection type. The following is an example from the FileHelpers source.

[TestClass]
public class GenericDatabaseStorageTests
{
    [TestMethod]
    public void CurrencyOracleExtractToFile( )
    {
        GenericDatabaseStorage<OracleConnection, OracleCommand> storage =
            new GenericDatabaseStorage<OracleConnection, OracleCommand>( 
                typeof(TestRecord), 
                "User Id=SHELL;Password=shell;Data Source=ora9dev"
            );

        storage.SelectSql = "SELECT * FROM CURRENCY";
        storage.FillRecordCallback = new FillRecordHandler( FillRecordOrder );

        FileDataLink.EasyExtractToFile( storage, "tempord.txt" );

        FileDataLink link = new FileDataLink( storage );
        link.ExtractToFile( "tempord.txt" );

        TestRecord[] res = (TestRecord[])CommonEngine.ReadFile(typeof(TestRecord), "tempord.txt");

        if ( File.Exists( "tempord.txt" ) )
            File.Delete( "tempord.txt" );

        Assert.AreEqual( 3, res.Length );

        Assert.AreEqual( "AED", res[ 0 ].CurrencyCode );
        Assert.AreEqual( "AFA", res[ 1 ].CurrencyCode );
        Assert.AreEqual( "ALL", res[ 2 ].CurrencyCode );
    }

    public void FillRecordOrder( object rec, object[ ] fields )
    {
        TestRecord record = ( TestRecord )rec;

        record.CurrencyCode = ( string )fields[ 0 ];
        record.Name = ( string )fields[ 1 ];
    }
}
shamp00
  • 11,106
  • 4
  • 38
  • 81
  • oh tht's great.Thanks a lot.Is there a way to get corresponding column names also into the file along with data..? – user1046415 Jul 31 '12 at 13:29
  • You can set `engine.HeaderText` as [answered elsewhere](http://stackoverflow.com/a/8258420/1077279). – shamp00 Jul 31 '12 at 15:10