using System.Data.OleDb; //命名空间
private void button1_Click(object sender, EventArgs e) 
{  
string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=student.xls; Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn)
string sql = "select * from [student$]"; //注意EXCEL数据库表形式
OleDbCommand cmd = new OleDbCommand(sql, conn);
OleDbDataAdapter oda
= new OleDbDataAdapter(cmd);
DataSet ds
= new DataSet();
oda.Fill(ds,
"student");
dataGridView1.DataSource
= ds.Tables[0];  
}

相关文章:

  • 2021-10-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-01
  • 2022-01-26
  • 2021-11-05
  • 2021-12-05
  • 2021-11-29
  • 2021-09-23
相关资源
相似解决方案