zoukankan      html  css  js  c++  java
  • C# 读取 Access

    通过using语句实现非GC资源的自动回收。

    还需要有try…catch…之类的异常检测语句,检测file.exist。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

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

    namespace ReadAccess
    {
        class Program
        {
            static void Main(string[] args)
            {
                using (OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=school.mdb"))
                {
                    conn.Open();

                    string sql = "select * from sheet1 where student='stu2'";

                    OleDbCommand command;

                    command = new OleDbCommand(sql, conn);

                    using (OleDbDataReader reader = command.ExecuteReader())
                    {
                        //1次读取1个记录
                        while (reader.Read())
                        {

                            for (int i = 0; i < reader.FieldCount; i++)
                            {

                                Console.Write("{0} ", reader[i]);

                            }

                            Console.WriteLine();

                        }
                    }
                }
            }
        }
    }

  • 相关阅读:
    poj 2425 AChessGame(博弈)
    poj2975 Nim 胜利的方案数
    hdu 5724 SG+状态压缩
    hdu 5274 Dylans loves tree(LCA + 线段树)
    hdu 5266 pog loves szh III(lca + 线段树)
    hdu 4031 attack 线段树区间更新
    51 nod 1188 最大公约数之和 V2
    51nod 1040 最大公约数之和(欧拉函数)
    51nod 1035:最长的循环节
    Nim游戏(组合游戏Combinatorial Games)
  • 原文地址:https://www.cnblogs.com/johnpher/p/2872624.html
Copyright © 2011-2022 走看看