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;
}
这里的Sheet1$就是那个Excel里的表一~名字不一样或者需要其他的表就改吧~