写了一段程序,和外面比对下来是一样的,
=============================================
string strPath = TextBox1.Text.ToString(); string mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '" + strPath + "';Extended Properties=Excel 8.0";
OleDbConnection cnnxls = new OleDbConnection(mystring);
OleDbDataAdapter myDa = new OleDbDataAdapter("select * from [" + TextBox3.Text.ToString() + "$]", cnnxls);
DataSet myDs = new DataSet();
myDa.Fill(myDs,"table1"); if (myDs.Tables["table1"].Rows.Count != 0)
{
Response.Write("<table border=1>");
for (int i = 0; i < myDs.Tables["table1"].Rows.Count; i++)
{
Response.Write("<tr>");
for (int j = 0; j < myDs.Tables["table1"].Columns.Count; j++)
{
Response.Write("<td>");
Response.Write(myDs.Tables["table1"].Rows[i][j].ToString());
Response.Write("</td>");
}
Response.Write("</tr>");
}
Response.Write("</table>");
}
=============================================
为什么我读出来的DATASET总归是少第一行数据呢?比如a 1 aa
b 2 bb
c 3 cc我读出来就是b 2 bb
c 3 cc
少一行
=============================================
string strPath = TextBox1.Text.ToString(); string mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '" + strPath + "';Extended Properties=Excel 8.0";
OleDbConnection cnnxls = new OleDbConnection(mystring);
OleDbDataAdapter myDa = new OleDbDataAdapter("select * from [" + TextBox3.Text.ToString() + "$]", cnnxls);
DataSet myDs = new DataSet();
myDa.Fill(myDs,"table1"); if (myDs.Tables["table1"].Rows.Count != 0)
{
Response.Write("<table border=1>");
for (int i = 0; i < myDs.Tables["table1"].Rows.Count; i++)
{
Response.Write("<tr>");
for (int j = 0; j < myDs.Tables["table1"].Columns.Count; j++)
{
Response.Write("<td>");
Response.Write(myDs.Tables["table1"].Rows[i][j].ToString());
Response.Write("</td>");
}
Response.Write("</tr>");
}
Response.Write("</table>");
}
=============================================
为什么我读出来的DATASET总归是少第一行数据呢?比如a 1 aa
b 2 bb
c 3 cc我读出来就是b 2 bb
c 3 cc
少一行
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties="Excel 8.0;HDR=No;IMEX=1";