从Access数据库收集数据

从Access数据库收集数据

本文介绍了从Access数据库收集数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想收集来自Access数据库的某些表中的一些数据,我发现了一些解决方案在网上,但我还没有找到方法来填充数据表或数据集,并正确地获得每个单场。

I want to gather some data from some tables of an Access Database, I've found some solutions online, but I haven't found ways to fill a datatable, or dataset, and get each single field properly.

时我更容易获得整个表,然后得到的只是我想要的信息,或者我应该做大量的搜索在Access数据库得到正是我想每一次?任何code片段呢?

Is it easier for me to get whole tables then get just the info that i want, or should I make a lot of searches in the access DB getting just what i Want each time? Any code snippets for it?

信息:

  • 在Access数据库处于ACCDB文件中,没有用户名或密码
  • 在我目前使用VB.NET,但它如果你在C#中回答不要紧
  • The Access Database is in an ACCDBfile, with no user or password
  • I'm currently using VB.NET, but itdoesn't matter if you answer in C#

- - 中国子问题
 http://stackoverflow.com/questions/2373355/connecting-to-accdb-format-ms-access-database-through-oledb

----
Sub question:
http://stackoverflow.com/questions/2373355/connecting-to-accdb-format-ms-access-database-through-oledb

推荐答案

从的,您使用的:

From here, you use the OleDbDataReader:

using System;
using System.Data;
using System.Data.Common;
using System.Data.OleDb;

class MainClass
{
  static void Main(string[] args)
  {
    string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;data source=C:\\Northwind.mdb";

    OleDbConnection conn = new OleDbConnection(connectionString);

    string sql = "SELECT * FROM Orders";

    OleDbCommand cmd = new OleDbCommand(sql, conn);

    conn.Open();

    OleDbDataReader reader;
    reader = cmd.ExecuteReader();

    while (reader.Read())
    {
      Console.Write(reader.GetString(0).ToString() + " ," );
      Console.Write(reader.GetString(1).ToString() + " ," );
      Console.WriteLine("");
    }

    reader.Close();
    conn.Close();
  }
}

这篇关于从Access数据库收集数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 07:43