NetElite

导航

 

/*
Description:
This is an example program that demonstrate how to use ADO.net to connect
the SQL server and retrieve data from it under the Console Mode.

Author:Fenghua Lu
Date: May 2, 03
*/
using System;
using System.Data;
using System.Data.OleDb;

class DbTest{
public static void Main(){
string sConnectionString="Provider=sqloledb;Data Source=localhost;Initial Catalog=polaris;User Id=sa;Password=polaris;";    
   OleDbConnection objConn=new OleDbConnection(sConnectionString);
      objConn.Open();
     
      OleDbCommand  objCmdSelect=new  OleDbCommand("select * from userinfo");
   OleDbDataAdapter objAdapter1=new OleDbDataAdapter();

   objAdapter1.SelectCommand=objCmdSelect; 
   objAdapter1.SelectCommand.Connection=objConn;
   
   IDataReader reader= objCmdSelect.ExecuteReader();
   
           while (reader.Read())
            {
             Console.WriteLine(@"{0:d} | {1,20:c} | {2:c} | {3}",reader["id"], reader["username"],reader["birthday"],reader["memo"]);
             Console.WriteLine("---------------------------------------------------------------------------");
            } 
        
   objConn.Close(); 
}
}

posted on 2004-11-29 10:48  Gravitonium  阅读(443)  评论(0编辑  收藏  举报