之前做这个东西的时候,在网上搜了不少代码,可是发现许多代码都不能完整的运行,总是有各种各样的错误,让人好生烦恼,今天终于写出来了,与大家分享。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private DataSet thisDataSet = null;
private void button1_Click(object sender, EventArgs e)
{
try
{
string str=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+textBox1.Text+";Extended Properties=Excel 8.0";
OleDbConnection myConn = new OleDbConnection(str);
myConn.Open();
OleDbDataAdapter thisAdapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", myConn);
//