C# EXCEL 데이터베이스 연결

2986 단어 Excel

  
    
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 ];  
}

좋은 웹페이지 즐겨찾기