[Mono-list] Problem in getting Console output

Azher Amin azher at niit.edu.pk
Sat Jul 7 10:25:43 EDT 2007


I am new to mono and was running the basic MS-SQL Connectivity. I am 
running everthing in the Linux console The program connects successfuly, 
table and userfields are OK (i tested but providing wrong password and 
unknown table and it throws error).

There is one row in the table. However I am not able to see the output, 
Plz suggest where I am wrong.


DB: azher
Table: users
Fields: name (string 20), age int (4)
Program "Test.cs"

 using System;
 using System.Data;
 using System.Data.SqlClient;

 public class Test
    public static void Main(string[] args)
       string connectionString =
          "Server=;" +
          "Database=azher;" +
          "User ID=sa;" +
       IDbConnection dbcon;
       using (dbcon = new SqlConnection(connectionString)) {
           using (IDbCommand dbcmd = dbcon.CreateCommand()) {
               string sql =
                   "SELECT name, age " +
                   "FROM users";
               dbcmd.CommandText = sql;
               using (IDataReader reader = dbcmd.ExecuteReader()) {
                   while(reader.Read()) {
                       string FirstName = (string) reader["name"];
                       int Age  = (int) reader["age"];
                       System.Console.WriteLine("Name: " +
                            FirstName + " " + Age);

I tried with:
mcs Test.cs -r:System.Data
mono Test.exe

mcs Test.cs -r:System.Data.dll
mono Test.exe

More information about the Mono-list mailing list