标题:c#与access连接的问题
取消只看楼主
sgrrzbc
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-8-14
结帖率:66.67%
已结贴  问题点数:20 回复次数:0 
c#与access连接的问题
using System;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace DataSet
{
    class Program
    {
        static void Main(string[] args)
        {  // Creat conection object for Microsoft Access OLE DB Provider;
            //note @ sign prefacing string literal so backslashes in path name;
            //work
            OleDbConnection thisConnection = new OleDbConnection(
                @"provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\c#教程\协和医院.mdb");
            // Creat DataAdapter object
            OleDbDataAdapter thisAdapter = new OleDbDataAdapter(
                "SELECT ID, 字段1,字段2,字段3,字段4,字段5,字段6,字段7,字段8  FROM Sheet1", thisConnection);
            // Create DataSet to contain related data tables,rows and columns
            System.Data.DataSet thisDataSet = new System.Data.DataSet();
            //Fill DataSet using query defined previously for DataAdapter
            thisAdapter.Fill(thisDataSet, "Sheet1" );
            foreach (DataRow theRow in thisDataSet.Tables["Sheet1 "].Rows)
            {
                Console.WriteLine(theRow["ID"] + "\t" + theRow["字段1"] + "\t" +
                    theRow[" 字段2"] + "\t" + theRow["字段3"] + "\t" +
                    theRow["字段4"] + "\t" +
                    theRow[" 字段5"] + "\t" +
                    theRow[" 字段6"] + "\t" +
                    theRow[" 字段7"] + "\t" +
                    theRow[" 字段8"]);
            }
            thisConnection.Close();
            Console.Write("Program finished,press Enter /Return to continue:");
            Console.ReadLine();
        }

        }
    }



这句thisDataSet.Tables["Sheet1 "].Rows  未将对象引用设置到对象的实例,不知道怎么改,希望大家帮忙啊,谢谢
搜索更多相关主题的帖子: access 
2010-08-14 23:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-315724-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.127218 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved