http://filehelpers.sourceforge.net/example_sqlstorage_extract.html
上面的示例连接到SQl服务器。
我的要求是连接到Oracle DB。我在filehelpers中找不到可以用来连接到oracle DB的类。如果您有任何想法,请帮忙。非常感谢。
答案 0 :(得分:1)
您可以使用采用任何ADO.NET GenericDatabaseStorage<T>
类型的IDBConnection
类。以下是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 ];
}
}