会在string a = ds.Tables["sheet1$"].Rows[0][0].ToString();报错。
提示说:NullReferenceException was unhandled by user code.
Object reference not set to an instance of an object.
不是很明白有什么地方出错了吗?是根本没连接到表吗?代码如下:
                    DataSet ds = null;
                    string strconn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + savefilepath + ";" + "Extended Properties='Excel 8.0;HDR=NO;IMEX=1;'";
                    OleDbConnection conn = new OleDbConnection(strconn);
                    try
                    {                        conn.Open();
                        OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from [Sheet1$]", strconn);
                        ds = new DataSet();
                        myCommand.Fill(ds, "[sheet1$]");
                        string a = ds.Tables["sheet1$"].Rows[0][0].ToString();
                    }
                    finally
                    {                        conn.Close();
                    }