[Mono-dev] Interactive C# - running a script

Daniel Morgan monodanmorg at yahoo.com
Wed Oct 15 11:41:58 EDT 2008


I would like to use the csharp interactive shell to run a script file.  

Is this possible?

Here is an example (not tested):

linux$ cat script-file > csharp
Connecting...
Copying...
Done.
linux$

Example script (not tested):

LoadLibrary("System.Data.dll");
LoadLibrary("System.Data.OracleClient");
using System.Data;
using System.Data.SqlClient;
using System.Data.OracleClient;
Console.WriteLine("Connecting...");
SqlConnection sourcedb = SqlConnection("...");
sourcedb.Open();
SqlCommand sourceCmd = sourcedb.CreateCommand();
sourceCmd.CommandText = "SELECT somecolumn FROM sometable WHERE C = 'A'";
string value = (string) sourceCmd.ExecuteScalar();
OracleConnection targetdb = OracleConnection("...");
targetdb.Open();
Console.WriteLine("Copying...");
OracleCommand targetCmd = targetdb.CreateCommand();
targetCmd.CommandText = "INSERT INTO sometable (column1) VALUES ('" + value + "')";
targetCmd.ExecuteNonQuery();
targetCmd.CommandText = "COMMIT";
targetCmd.ExecuteNonQuery();
sourcedb.Close();
targetdb.Close();
Console.WriteLine("Done.");





      


More information about the Mono-devel-list mailing list