App Programming/C#2008. 3. 8. 00:37

파일 찾기 버튼을 클릭하면...

            OpenFileDialog OpenFileDlg =new OpenFileDialog();

            OpenFileDlg.Filter="모든 파일(*.*)|*.*|xls(*.xls)|*.xls";

            OpenFileDlg.ShowDialog();

            string path=OpenFileDlg.FileName;          

            string connection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=Excel 8.0;";                      

            OleDbConnection cnt = new OleDbConnection(connection);

            cnt.Open();                                                                                                  

            OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", cnt);

            OleDbDataAdapter adp = new OleDbDataAdapter();

            adp.SelectCommand = cmd;

            DataSet ds = new DataSet();

            adp.Fill(ds);                 // <- System.Data.OleDb.OleDbException: 외부 테이블 형식이 잘못되었습니다

            this.dataGrid3.DataSource = ds.Tables[0].DefaultView;

            cnt.Close();



Posted by BAGE