Tuesday, June 20, 2006

First ever ADO.NET program ;)

First ever ADO.NET program written by me ;)

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

class firstadocs {
static void Main(string[] args)
{
string ConnectionString ="server=mono-server;database=monotest;user id=monotester;password=monotester;";

SqlConnection conn = new SqlConnection(ConnectionString);
string sql = "SELECT * FROM tbl1";
SqlCommand cmd = new SqlCommand (sql, conn);
conn.Open ();
SqlDataReader reader = null;
reader = cmd.ExecuteReader();
while (reader.Read())
{
Console.Write(reader.GetString(0).ToString() + " ," );
Console.Write(reader.GetString(1).ToString() + " ," );
Console.WriteLine("");
}
// Close reader
reader.Close();
// Close the connection
conn.Close();
}
}

Thanks to senga for helping me in understanding ADO.NET. Also going through the book 'A Programmers Guide to ADO.NET in C#' !

0 Comments:

Post a Comment

<< Home