C# : ADO.NET 读取 Access mdb

mdb_ADO.cs 示例代码:

using System;
using System.Data;
using System.Data.OleDb;
using System.IO;

namespace mdb_ADO
{
    class Program
    {
        static void Main(string[] args)
        {
            string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Northwind.mdb";
            OleDbConnection Conn = new OleDbConnection(connStr);
            Conn.Open(); 
            // get records from the table
            string sql = "Select * from [产品]";

            // create a text writer to the new file
            string wfile = "产品.txt";
            StreamWriter writer = new StreamWriter(wfile, false);
            
            // create the data set command object
            // and the DataReader
            OleDbCommand cmd = new OleDbCommand(sql, Conn); 
            OleDbDataReader DR = cmd.ExecuteReader();
            while (DR.Read())
            {
                writer.WriteLine(DR["产品名称"].ToString() +"\t"+ DR["供应商"].ToString());
            }
            DR.Close(); 
            Conn.Close();
            writer.Close();
        }
    }
}


c# 读取.mdb中的栅格数据 string path = @"E:\zxl\npgDB.mdb"; axMapControl1.ActiveView.Clear(); axMapControl1.ActiveView.Refresh(); pFWorkspace = OpenAccessWorkspace(path, pFWorkspace); IFeatureLayer iflayer; iflayer = new FeatureLayerClass(); iflayer.FeatureClass = pFWorkspace.OpenFeatureClass("地标"); axMapControl1.AddLayer(iflayer, 0); IFeatureLayer featureLayer = iflayer; //this.axMapControl1.Map.get_Layer(0) as IFeatureLayer; IFeatureCursor featureCursor; IFeature feature; IGeometry geometry; IActiveView activeView = this.axMapControl1.ActiveView; ITopologicalOperator topo; featureCursor = featureLayer.FeatureClass.Search(null, false); feature = featureCursor.NextFeature(); ISpatialFilter spatialFilter = new SpatialFilterClass(); IFeatureSelection featureSelection; if (feature != null) { MessageBox.Show("if","tishi"); topo = feature.Shape as ITopologicalOperator; //double bufferLength = ConvertPixelsToMapUnits(activeView, 2); //geometry = topo.Buffer(bufferLength); geometry = topo.Buffer(1000); spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; spatialFilter.Geometry = geometry; spatialFilter.GeometryField = featureLayer.FeatureClass.ShapeFieldName; spatialFilter.SubFields = "name"; spatialFilter.WhereClause = "name='第一教学楼'"; featureSelection = featureLayer as IFeatureSelection; featureSelection.SelectFeatures(spatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false); ISelectionSet selectionSet = featureSelection.SelectionSet; ICursor cursor; selectionSet.Search(null, true, out cursor); featureCursor = cursor as IFeatureCursor; feature = featureCursor.NextFeature(); while (feature != null) { MessageBox.Show("while", "tishi"); this.axMapControl1.Map.SelectFeature(featureLayer, feature); feature = featureCursor.NextFeature(); } // activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, geometry.Envelope); } } private void button13_Click(object sender, EventArgs e) { string path = @"E:\zxl\npgDB.mdb"; axMapControl1.ActiveView.Clear(); axMapControl1.ActiveView.Refresh(); pFWorkspace = OpenAccessWorkspace(path, pFWorkspace); IFeatureLayer iflayer; iflayer = new FeatureLayerClass(); iflayer.FeatureClass = pFWorkspace.OpenFeatureClass("地标"); axMapControl1.AddLayer(iflayer, 0); Filter filter = new Filter(); ISpatialFilter filter1=new SpatialFilterClass(); filter1.WhereClause=""; //filter1. = "CITY_NAME = 'Phoenix'"; //Envelope envelope = new Envelope(-119, 32, -113, 35); //filter1.Geometry = envelope; //DisplayBuffer displaybuffer = new DisplayBuffer(); //displaybuffer.Distance = 200; //displaybuffer.Units = BufferUnits.Miles; //SimpleRenderer bufferrenderer = new SimpleRenderer(); //SimpleFillSymbol sfs = new SimpleFillSymbol(); //sfs.Color = System.Drawing.Color.Yellow; //sfs.Transparency = 50.0; //bufferrenderer.Symbol = sfs; //FeatureLayer bufferlayer = iflayer.CreateBufferLayer(filter, displaybuffer, bufferrenderer, "mybuffer"); //mapview.Layers.Add(bufferlayer); //mapview.Draw(); Geoprocessor gp=new Geoprocessor();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值