• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

c#读取ACCESS数据库

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            FileStream fs = new FileStream("ak-1.csv", FileMode.Create);

            OleDbConnection conn = null;
            OleDbDataReader reader = null;
            conn = new OleDbConnection(
            "Provider=Microsoft.Jet.OLEDB.4.0; " +
            "Data Source=" + ("C:/Users/Ali/Documents/aaaaa.mdb"));
            conn.Open();
            OleDbCommand cmd =
                new OleDbCommand("Select * FROM 用户信息", conn);
            reader = cmd.ExecuteReader();
            int count = 0;
            while (reader.Read())
            {
                count++;
                if (count % 50000 == 0)
                {
                    fs = new FileStream("ak-"+(count/50000+1)+".csv", FileMode.Create);
                }

                String x = getsss(reader, 0) + "," + getsss(reader, 1) + "," +
                getsss(reader, 2) + "," + getsss(reader, 3) + "," +
                getsss(reader, 4) + "," + getsss(reader, 5) + "," +
                getsss(reader, 6) + "," + getsss(reader, 7) + "," +
                getsss(reader, 8) + "," + getsss(reader, 9)+"\r\n";
                    //Console.WriteLine(x);
                
                



                byte[] aaaaa = System.Text.Encoding.Default.GetBytes(x);
                //reader.Read();
                //Console.WriteLine(reader.GetString(2));
                fs.Write(aaaaa,0,aaaaa.Length);
                fs.Flush();


            }
            fs.Close();
            





        }


        private static String getsss(OleDbDataReader reader,int a) {

        try
        {
                return reader.GetString(a);

        }
        catch (Exception e)
        {
                return "";
                
            }
            


            

        }

    }


    




}

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++头文件中声明全局变量要注意的几点发布时间:2022-07-14
下一篇:
cocos2d-x3.0在C++中调用lua函数发布时间:2022-07-14
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap