using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Odbc;
using System.Data.OleDb;

namespace ODBCtest
{
    class Program
    {
        static void Main(string[] args)
        {
            //ODBC连接
            string conString = "DSN=tian"; //tian表示ODBC的用户数据源名
            string sql = "select count(*) from stuinfo"; //stuinfo为用户数据源绑定的数据库中的一个表
            OdbcConnection con = new OdbcConnection(conString);
            con.Open();
            OdbcCommand com = new OdbcCommand(sql, con);
            int i = Convert.ToInt32(com.ExecuteScalar());
            Console.WriteLine(i);


            //OLEDB连接
            string conString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\tian.mdb"; //连接Access数据库
            string sql = "select count(*) from stuinfo"; 
            OleDbConnection con = new OleDbConnection(conString);
            con.Open();
            OleDbCommand com = new OleDbCommand(sql, con);
            int i = Convert.ToInt32(com.ExecuteScalar());
            Console.WriteLine(i);
        }
    }
}

posted on 2010-07-14 19:19  aparche  阅读(10475)  评论(0编辑  收藏  举报