using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
namespace 批量写入坐标
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection conn;
string strSQL = "";
conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + @"F:\research\空间可达性分析\沈阳数据\最终的poi数据\新建个人地理数据库.mdb");
conn.Open();
strSQL = "Select OBJECTID,Lon,Lat,Lon_1,Lat_1 from Export_Output";
if (strSQL != "")
{
OleDbCommand cmd = new OleDbCommand(strSQL, conn);
cmd.ExecuteNonQuery();
DataSet myds = new DataSet();
OleDbDataAdapter oda = new OleDbDataAdapter(strSQL, conn);
oda.Fill(myds);
FileStream stream = new FileStream(Application.StartupPath + "\\20200212.txt", FileMode.Create);//fileMode指定是读取还是写入
StreamWriter writer = new StreamWriter(stream);
for (int intI = 0; intI < myds.Tables[0].Rows.Count; intI++)
{
writer.WriteLine(myds.Tables[0].Rows[intI][0].ToString()+"|"+ myds.Tables[intI].Rows[0][1].ToString()+"|"+ myds.Tables[0].Rows[intI][2].ToString()+"|"+ myds.Tables[0].Rows[intI][3].ToString()+"|"+ myds.Tables[0].Rows[intI][4].ToString());//写入一行,写完后会自动换行
}
writer.Close();//释放内存
stream.Close();//释放内存
}
conn.Close();
this.Close();
}
}
}