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();
                    }

                }

            }
  • 相关阅读:
    Java面试题
    Mybatis插入数据返回自增主键
    SpringBoot前端给后端传list
    Mybatis学习—XML映射文件
    数据库基础——数据库事务的四大特性以及事务的隔离级别
    数据库基础——锁管理
    数据库基础——索引
    计算机网络面试核心
    蚂蚁金服电话面试问题
    京东架构
  • 原文地址:https://www.cnblogs.com/wudingfeng/p/1086946.html
Copyright © 2011-2022 走看看