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 未将对象引用设置到对象的实例,不知道怎么改,希望大家帮忙啊,谢谢