部分代码:
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; namespace WindowsFormsApp8 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string Path = textBox1.Text.Trim(); string sql = textBox2.Text.Trim(); //string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;"; string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;"; OleDbConnection conn = new OleDbConnection(connStr); conn.Open(); OleDbDataAdapter myCommand = null; DataSet ds = null; myCommand = new OleDbDataAdapter(sql, connStr); ds = new DataSet(); myCommand.Fill(ds, "table1"); dataGridView1.DataSource = ds.Tables[0]; conn.Dispose(); } private void Form1_Load(object sender, EventArgs e) { textBox1.Text = Properties.Settings.Default.defaultPath; textBox2.Text = Properties.Settings.Default.defaultSQL; } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { Properties.Settings.Default.defaultPath = textBox1.Text.Trim(); Properties.Settings.Default.defaultSQL = textBox2.Text.Trim(); Properties.Settings.Default.Save(); } } }
标签:Settings,C#,Text,EXCEL,System,文本框,Default,using,Properties From: https://www.cnblogs.com/sound-of-wind-rain/p/17365158.html