[Mono-list] Problem in getting Console output
Azher Amin
azher at niit.edu.pk
Sat Jul 7 10:25:43 EDT 2007
Hi,
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.
Regards
-Azher
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=10.10.10.3;" +
"Database=azher;" +
"User ID=sa;" +
"Password=1234;";
IDbConnection dbcon;
using (dbcon = new SqlConnection(connectionString)) {
dbcon.Open();
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
and:
mcs Test.cs -r:System.Data.dll
mono Test.exe
More information about the Mono-list
mailing list