I wanted to try out the new tool called csharp which allows you to interfactively enter commmands in C# and it compiles and run them. In my case, I wanted to see it connecting to a database. Here is my results - typos and all:
danmorg@danspc:~/monosvn/monoinstall/etc/mono> csharp
Mono C# Shell, type "help;" for help
Enter statements below.
csharp> LoadAssembly("System.Data.dll");
csharp> using System.Data;
csharp> using System.Data.Common;
csharp> DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OracleClient");
csharp> IDbConnection con = (IDbConnection) factory.CreateConnection();
csharp> con.ConnectionString = "server=testdb;user id=scott;password=tiger";
"server=testdb;user id=scott;password=tiger"
csharp> con.Open();
csharp> con.State;
Open
csharp> IDbCommand cmd = con.CreateCommand();
csharp> cmd.CommadText = "select 'one' as num from dual union select 'two' from dual union select 'three' from dual";
csharp> cmd.CommandText = "select 'one' as num from dual union select 'two' from"select 'one' as num from dual union select 'two' from dual union select 'three' from dual"
csharp> IDataReader reader = cmd.ExecuteReader();
csharp> whlie (reader.Read())
> Console.WriteLine(reader.GetString(0));
csharp> while (reader.Read())
> Console.WriteLine(reader.GetString(0));
one
three
two
csharp> reader.Close();
csharp> con.Close();
csharp> con.State;
Closed
The errors I got usually were due to typos. I didn't have to re-type everything, just clicked the up arrow to get a command in my history.
Also, here are two important commands to remember:
To get help, type: help;
To quit, type:
quit: