11 "Data Source=" + this.tBFileAddress.Text.Trim() + ";" +
12 "Extended Properties='Excel 8.0;HDR=YES;IMEX=1;'"; 13 14// Create connection object by using the preceding connection string. 15 OleDbConnection objConn =new OleDbConnection(sConnectionString); 16 17// Open connection with the database. 18 objConn.Open(); 19 20// The code to follow uses a SQL SELECT command to display the data from the worksheet. 21 22// Create new OleDbCommand to return data from worksheet. 23 OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM ["+tBsheet.Text.Trim()+"$] where 料號<>''", objConn); 24 25// Create new OleDbDataAdapter that is used to build a DataSet 26// based on the preceding SQL SELECT statement. 27 OleDbDataAdapter objAdapter1 =new OleDbDataAdapter(); 28 29// Pass the Select command to the adapter. 30 objAdapter1.SelectCommand = objCmdSelect; 31 32// Create new DataSet to hold information from the worksheet. 33 DataSet objDataset1 =new DataSet(); 34 35// Fill the DataSet with the information from the worksheet. 36 objAdapter1.Fill(objDataset1,"料號基本資料"); 37 38 Thread.Sleep(200); 39 statusBarPanel4.Text="正在讀取數據["+objDataset1.Tables["料號基本資料"].Rows.Count+"]"; 40 Thread.Sleep(500); 41// Clean up objects. 42 objConn.Close(); 43 44 dtbSearch=objDataset1.Tables["料號基本資料"]; 45 46 progressBar1.Value=30; 47 48 } 49catch 50 }