zoukankan      html  css  js  c++  java
  • 多种文件做数据源的连接方法

    下面有详细方法:
    http://www.connectionstrings.com/default.aspx
    导入的文件下必须有一个命名为"Schema.ini"的配置文件,如何配置,上面的网址里有详细说明.
    如下示例:
    string dir=Path.GetDirectoryName(filePath);
            
    string filename=Path.GetFileName(filePath);
            
    string conStr = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}\\;Extended Properties=\"text;HDR=Yes;FMT=Delimited(,)\";", dir);
            
    using (OleDbConnection oledbCon = new OleDbConnection(conStr))
            
    {
                OleDbDataReader reader
    =null;
                OleDbCommand oledbCom 
    = new OleDbCommand();
                oledbCom.Connection 
    = oledbCon;
                oledbCom.CommandText 
    = string.Format("select top 1 * from {0}", filename);

                
    try
                
    {
                    oledbCon.Open();
                    reader 
    = oledbCom.ExecuteReader();            }

                
    catch (SqlException e)
                
    {
                    
    throw new Exception(e.Message);
                }

                
    catch (Exception ex)
                
    {
                    
    throw new Exception(ex.Message);
                }

                
    finally
                
    {
                    
    if (reader != null)
                    
    {
                        reader.Close();
                    }

                }

            }
  • 相关阅读:
    weexpack build android 和 weexpack run android 报错 及 解决方案
    weexapp 开发流程(三)其他页面创建
    svn 创建分支、切换分支 及 合并分支 操作
    github 新建远程仓库 及 删除远程仓库
    photoshop 前端常用技巧
    vue2.0 常用的 UI 库
    weex 小结
    Android-studio 连接真机 调试weex项目
    js中Math之random,round,ceil,floor的用法总结
    基于canvas图像处理的图片 灰色图像
  • 原文地址:https://www.cnblogs.com/wudingfeng/p/1086946.html
Copyright © 2011-2022 走看看