Hi.
I wrote a program that connects to an excel database but it makes an error in connection string line.
Here's the code:
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++; }
|
It makes a runtime error on lines 1 and 2 and says:
"Format of the Initialization string does not conform to specification starting at index 93."
What's the problem?
BTW, I use office 2007, does it makes problem?
Thanks :-)
Majid KamaliPosted Jan 23, 2011, 10:09 AM
What's the problem.
Raghvendr SinghPosted Jan 22, 2011, 5:54 AM
Try this one
OleDbConnection Connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\DataBase2.xls;" +
"Extended Properties=Excel 8.0;HDR=Yes;IMEX=1;");