当前位置: 代码迷 >> C# >> 关于ADODB提示“不支持连接表达式”的有关问题
  详细解决方案

关于ADODB提示“不支持连接表达式”的有关问题

热度:473   发布时间:2016-05-05 05:32:24.0
关于ADODB提示“不支持连接表达式”的问题
先附上代码如下:

            ADODB.Recordset rs = new ADODB.Recordset();
            OleDbDataAdapter ad = new OleDbDataAdapter();
            DataTable dt = new DataTable();
            string connStr = "";
            if (FPath.Substring(FPath.Length - 4) == ".xls")
            {
                connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FPath + ";Extended Properties=Excel 8.0";

            }
            else
            {
                connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FPath + ";Extended Properties=Excel 12.0";
            }
            ADODB.Connection aconn = new ADODB.Connection();
            try
            {
                aconn.Open(connStr);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            string strsql = "select * from [Sheet1$] right join [Sheet2$] on [Sheet1$F$]=[Sheet2$D$] and [Sheet1$G$]=[Sheet2$E$]";
            try
            {
                rs.Open(strsql, aconn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, (int)ADODB.CommandTypeEnum.adCmdText);
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ad.Fill(dt, rs);
            rs.Close();
            aconn.Close();

        在运行后抛出异常“不支持连接表达式”。之前我使用OLEDB做类似操作也得到相同提示,想请教各路大侠,是我的SQL语句有错,还是ADODB不支持连接类的SQL语句?
    我想对2张EXCEL表做右连接的SQL操作,再显示出来,请问有什么好的办法可以实现?如果可以还请各路大侠附上具体代码,小弟拜谢啦~
------解决思路----------------------
你还是考虑先把不同工作簿都分别读到datatable里(放到一个dataset中)
然后使用LINQ内存处理吧
excel毕竟不是数据库
------解决思路----------------------
1:Excel 8.0  后边加个英文分号试试
2:查出数据,使用linq  to  DataSet 中的join on  关键字进行关联查询。具体 msdn
  相关解决方案