Excel中的From子句语法错误


 public void SetConnection(string text1, string text2, string text3, string text4, string text5, string text6, string text7)
    {

        connectionString1 = "Initial Catalog=testdb; Data Source=work\sqlexpress";


        database = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\Users\test.xls';Extended Properties= "Excel 8.0;HDR=Yes;IMEX=1";");
        database.Open();
        database1 = new OleDbConnection("Provider=SQLOLEDB.1;" + connectionString1);
        database1.Open();
    }
data1 = DataAccess.DatabaseTables("SELECT * from [Sheet1$])", DataAccess.database); 
 public DataTable DatabaseTables(string QueryString, OleDbConnection DataConnection)
    {
        OleDbCommand SQLQuery = new OleDbCommand();
        DataTable data = null;
        SQLQuery.Connection = null;
        OleDbDataAdapter dataAdapter = null;
        SQLQuery.CommandText = QueryString;
        SQLQuery.Connection = DataConnection;
        data = new DataTable();
        dataAdapter = new OleDbDataAdapter(SQLQuery);
        dataAdapter.Fill(data);
        return data;
    }

对于从data1开始的代码行,我得到异常"语法错误"。这一行调用它下面的函数DatabaseTables,它生成这个异常。我还包括在fn SetConnection中使用jet等的连接字符串。我认为问题可能是连接字符串本身。目前,我不得不离开excel文件打开,以防止"无法解密"的错误。我确实尝试了ACE驱动程序,但出现了错误。excel工作簿保存为97-03工作簿

change

data1 = DataAccess.DatabaseTables("SELECT * from [Sheet1$])", DataAccess.database); 

data1 = DataAccess.DatabaseTables("SELECT * from [Sheet1$]", DataAccess.database);

有一个额外的右括号。

相关内容

  • 没有找到相关文章

最新更新