EXCEL導入DATASET的代碼我就寫在下面吧,可以幫助一下新手~
public void ExcelToDS(string Path)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection myConn = new OleDbConnection(strConn);
myConn.Open();
string strCom = "SELECT * FROM [Sheet1$]";
OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
myDataSet = new DataSet();
myCommand.Fill(myDataSet, "[Sheet1$]");
myConn.Close();
dataGridView1.DataMember = "[Sheet1$]";
dataGridView1.DataSource = myDataSet;
}