OleDbConnection Connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\DataBase2.xls;" + "Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";"); OleDbDataAdapter Adapter = new OleDbDataAdapter("Select * from Sheet1", Connection); DataSet DS = new DataSet(); DataTable DT = new DataTable();
Adapter.Fill(DS); DT = DS.Tables[0];
TextBox[,] TB = new TextBox[DT.Rows.Count, DT.Columns.Count]; for (int i = 0; i < DT.Rows.Count; i++) { for (int j = 0; j < DT.Columns.Count; j++) { TB[i, j] = new TextBox(); TB[i, j].Parent = this; TB[i, j].Size = new Size(30, TB[i, j].Size.Height); TB[i, j].Location = new Point(20 + j * TB[i, j].Size.Width, 20 + i * TB[i, j].Size.Height); TB[i, j].Show(); } }
int row = 0, col = 0; foreach (DataRow DR in DT.Rows) { for (col = 0; col < DT.Rows.Count; col++) TB[row, col].Text = DR[col].ToString(); row++; }
|