C# + Excel
-
Dear, I have one problem, when i connect from my app to excel and when display the result I lost 1 row, Why? Please help me
Socheat
-
Dear, I have one problem, when i connect from my app to excel and when display the result I lost 1 row, Why? Please help me
Socheat
-
You need to be more specific. How did you connect to the excel? Was it the first row you lost?
My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)
Dear I Use like this string strCnn=""; strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;"; strCnn += " Data source=" + openFileDialog1.FileName; strCnn += ";Extended Properties=Excel 8.0;"; OleDbConnection cn = new OleDbConnection(strCnn); cn.Open(); string strsql=""; strsql = "SELECT * FROM [sheet1$]"; OleDbDataAdapter da = new OleDbDataAdapter(strsql, cn); DataTable dt = new DataTable(); da.Fill(dt); int i=0; Application.DoEvents(); for (int k = 0; k < dt.Rows.Count; k++) { i++; dgvSource.Rows.Add(i.ToString(), dt.Rows[k][0].ToString()); } I got only 9 rows, but in fact in excel has 10 rows Thanks
Socheat
-
Dear I Use like this string strCnn=""; strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;"; strCnn += " Data source=" + openFileDialog1.FileName; strCnn += ";Extended Properties=Excel 8.0;"; OleDbConnection cn = new OleDbConnection(strCnn); cn.Open(); string strsql=""; strsql = "SELECT * FROM [sheet1$]"; OleDbDataAdapter da = new OleDbDataAdapter(strsql, cn); DataTable dt = new DataTable(); da.Fill(dt); int i=0; Application.DoEvents(); for (int k = 0; k < dt.Rows.Count; k++) { i++; dgvSource.Rows.Add(i.ToString(), dt.Rows[k][0].ToString()); } I got only 9 rows, but in fact in excel has 10 rows Thanks
Socheat
Which row is missing? Is it the first one? If it is then you will notice that it is being used as the column titles. Use
strCnn += ";Extended Properties=\"Excel 8.0;HDR=No;\"";
to stop using the first row as the column headers, the default is HDR=Yes.My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)
-
Which row is missing? Is it the first one? If it is then you will notice that it is being used as the column titles. Use
strCnn += ";Extended Properties=\"Excel 8.0;HDR=No;\"";
to stop using the first row as the column headers, the default is HDR=Yes.My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)
Dear I lose the first row. I have include string connection like you wrote "HDR=No;" already but i got error Cound not find installable ISAM, so how can i do?
Socheat
-
Dear I lose the first row. I have include string connection like you wrote "HDR=No;" already but i got error Cound not find installable ISAM, so how can i do?
Socheat
Apologies, I used used the incorrect syntax:
string strCnn = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=No;\"", openFileDialog1.FileName);
My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)
-
Apologies, I used used the incorrect syntax:
string strCnn = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=No;\"", openFileDialog1.FileName);
My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)
Dear, Thanks, it work well now
Socheat