当前位置: 首页>>代码示例>>C#>>正文


C# OleDbConnectionStringBuilder.ToString方法代码示例

本文整理汇总了C#中System.Data.OleDb.OleDbConnectionStringBuilder.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# OleDbConnectionStringBuilder.ToString方法的具体用法?C# OleDbConnectionStringBuilder.ToString怎么用?C# OleDbConnectionStringBuilder.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.OleDb.OleDbConnectionStringBuilder的用法示例。


在下文中一共展示了OleDbConnectionStringBuilder.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SqlServerDataProvider

 /// <summary>
 /// Initializes a new instance of the <see cref="SqlServerDataProvider"/> class.
 /// </summary>
 /// <param name="connectionString">The connection string.</param>
 internal SqlServerDataProvider(string connectionString)
     : base(connectionString)
 {
     var sqlConnectionStringBuilder = new SqlConnectionStringBuilder(this.ConnectionString);
     var oleDbConnectionStringBuilder = new OleDbConnectionStringBuilder();
     oleDbConnectionStringBuilder.DataSource = sqlConnectionStringBuilder.DataSource;
     oleDbConnectionStringBuilder.Provider = "SQLOLEDB";
     oleDbConnectionStringBuilder["database"] = sqlConnectionStringBuilder.InitialCatalog;
     oleDbConnectionStringBuilder["trusted_connection"] = sqlConnectionStringBuilder.IntegratedSecurity ? "yes" : "no";
     this.oleDbConnectionString = oleDbConnectionStringBuilder.ToString();
 }
开发者ID:jdaigle,项目名称:Centro,代码行数:15,代码来源:SqlServerDataProvider.cs

示例2: getCon

 public static OleDbConnection getCon()
 {
     if (conexion == null)
     {
         OleDbConnectionStringBuilder b = new OleDbConnectionStringBuilder();
         b.Provider = "Microsoft.ACE.OLEDB.12.0";
         b.DataSource = "cyberman.accdb";
         conexion = new OleDbConnection(b.ToString());
         conexion.Open();
     }
     return conexion;
 }
开发者ID:evilnapsis,项目名称:cibertim-msa,代码行数:12,代码来源:MSAConnection.cs

示例3: ExcelReader

        public ExcelReader(string path, bool hasHeaders, bool hasMixedData)
        {
            this.path = path;
            OleDbConnectionStringBuilder strBuilder = new OleDbConnectionStringBuilder();
            strBuilder.Provider = "Microsoft.Jet.OLEDB.4.0";
            strBuilder.DataSource = path;
            strBuilder.Add("Extended Properties", "Excel 8.0;"+
                "HDR=" + (hasHeaders ? "Yes" : "No") + ';' +
                "Imex=" + (hasMixedData ? "2" : "0") + ';' +
              "");

            strConnection = strBuilder.ToString();
        }
开发者ID:xyicheng,项目名称:Accord,代码行数:13,代码来源:ExcelReader.cs

示例4: getConnection

        /// <summary>
        /// ���� DataSource ���\���f�[�^�\�[�X�ւ̐ڑ�����݂܂��B
        /// </summary>
        /// <returns></returns>
        public override DbConnection getConnection()
        {
            OleDbConnectionStringBuilder connection_builder = new OleDbConnectionStringBuilder();

            //connection_builder.ConnectTimeout = base.loginTimeout;

            connection_builder["Provider"] = OLEDBProviderFactory.provider;
            connection_builder["Persist Security Info"] = base.integrated_security_;
            connection_builder["Data Source"] = base.data_source_;

            OleDbConnection result_connection = new OleDbConnection( connection_builder.ToString() );
            result_connection.InfoMessage += onInfoMessage;

            return result_connection;
        }
开发者ID:noqisofon,项目名称:liblazurite,代码行数:19,代码来源:OLEDataSource.cs

示例5: AddTable

 private static void AddTable(OleDbConnectionStringBuilder csb)
 {
     // check if table exists
     var con = new ADODB.Connection();
     con.Open(csb.ToString());
     var db = new ADOX.Catalog();
     db.ActiveConnection = con;
     try
     {
         var table = db.Tables[_logFileProcessor.TableName];
     }
     catch (COMException)
     {
         db.Tables.Append(_logFileProcessor.GetTable());
     }
     finally
     {
         con.Close();
     }
 }
开发者ID:egil,项目名称:alfac,代码行数:20,代码来源:Program.cs

示例6: ListSheetInExcel

        /*
         * Obtaining the name of the excel sheets and placing them on a list.
         * This method was obtained from: http://stackoverflow.com/questions/1164698/using-excel-oledb-to-get-sheet-names-in-sheet-order
         */
        public List<string> ListSheetInExcel(string filePath)
        {
            OleDbConnectionStringBuilder sbConnection = new OleDbConnectionStringBuilder();
            String strExtendedProperties = String.Empty;
            sbConnection.DataSource = filePath;

            List<string> listSheet = new List<string>();

            if (Path.GetExtension(filePath).Equals(".xls"))//for 97-03 Excel file
            {
                sbConnection.Provider = "Microsoft.Jet.OLEDB.4.0";
                strExtendedProperties = "Excel 8.0;HDR=Yes;IMEX=1";//HDR=ColumnHeader,IMEX=InterMixed
            }
            else if (Path.GetExtension(filePath).Equals(".xlsx"))  //for 2007 Excel file
            {
                sbConnection.Provider = "Microsoft.ACE.OLEDB.12.0";
                strExtendedProperties = "Excel 12.0;HDR=Yes;IMEX=1";
            }

            sbConnection.Add("Extended Properties", strExtendedProperties);

            using (OleDbConnection conn = new OleDbConnection(sbConnection.ToString()))
            {
                conn.Open();
                DataTable dtSheet = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

                foreach (DataRow drSheet in dtSheet.Rows)
                {
                    if (drSheet["TABLE_NAME"].ToString().Contains("$"))//checks whether row contains '_xlnm#_FilterDatabase' or sheet name(i.e. sheet name always ends with $ sign)
                    {
                        listSheet.Add(drSheet["TABLE_NAME"].ToString());
                    }
                }
            }
            return listSheet;
        }
开发者ID:jmori,项目名称:Employee_Checker_CSharp,代码行数:40,代码来源:Form1.cs

示例7: ListSheetInExcel

 /// <summary>
 /// Method: ListSheetInExcel
 /// This method will return a list of worksheets of the Excel file selected by name
 /// </summary>
 /// <returns>List of Worksheets of a single excel file</returns>
 public static List<string> ListSheetInExcel()
 {
     // List<T> for Excel Worksheets
     List<string> listSheet = new List<string>();
     // OleDbConnectionStringBuilder
     OleDbConnectionStringBuilder sbConnection = new OleDbConnectionStringBuilder();
     // String variable for ExtendedProperties
     String strExtendedProperties = String.Empty;
     // Set Datasource for Excel Connection
     sbConnection.DataSource = WinPath;
     // Evaluate which version is the current excel file
     // Excel 2003
     if (Version().Equals(ExcelVersion.ExcelVersion2003))
     {
         // Set provider for 2003
         sbConnection.Provider = "Microsoft.Jet.OLEDB.4.0";
         strExtendedProperties = "Excel 8.0;HDR=Yes;IMEX=0;ReadOnly=true";
     }
     // Excel 2007+
     else if (Version().Equals(ExcelVersion.ExcelVersion2007))
     {
         // Set provider for 2007+
         sbConnection.Provider = "Microsoft.ACE.OLEDB.12.0";
         strExtendedProperties = "Excel 12.0 Xml;HDR=Yes;IMEX=0";
     }
     // Add Extended Properties to Connection String
     sbConnection.Add("Extended Properties", strExtendedProperties);
     // Asign Connection string to static ExcelConnection variable
     ExcelConnection = sbConnection.ToString();
     // Use the current connection
     using (OleDbConnection conn = new OleDbConnection(sbConnection.ToString()))
     {
         // Open current connection
         conn.Open();
         // Get Tables Schema
         DataTable dtSheet = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
         // Loop through each row and get the table name
         foreach (DataRow drSheet in dtSheet.Rows)
         {
             // Check wheter row contains '_xlnm#_Filte rDatabase'
             // or sheet name(i.e. sheet name always ends with $ sign
             if (drSheet["TABLE_NAME"].ToString().Contains("$"))
             {
                 if (!drSheet["TABLE_NAME"].ToString().Contains("xlnm"))
                 {
                     // Add table name to List<T>
                     listSheet.Add(drSheet["TABLE_NAME"].ToString());
                 }
             }
         }
     }
     // Return List<T>
     return listSheet;
 }
开发者ID:maickher,项目名称:Asociacion,代码行数:59,代码来源:ExcelData.cs

示例8: GetStringConnection

        private string GetStringConnection(string fullFileName)
        {
            OleDbConnectionStringBuilder sbConnection = new OleDbConnectionStringBuilder();
            String strExtendedProperties = String.Empty;
            sbConnection.DataSource = fullFileName;
            if (Path.GetExtension(fullFileName).Equals(".xls"))//for 97-03 Excel file
            {
                sbConnection.Provider = "Microsoft.ACE.OLEDB.12.0";
                strExtendedProperties = "Excel 8.0;HDR=Yes;IMEX=1";//HDR=ColumnHeader,IMEX=InterMixed
            }
            else if (Path.GetExtension(fullFileName).Equals(".xlsx"))  //for 2007 Excel file
            {
                sbConnection.Provider = "Microsoft.ACE.OLEDB.12.0";
                strExtendedProperties = "Excel 12.0;HDR=Yes;IMEX=1";
            }
            sbConnection.Add("Extended Properties", strExtendedProperties);

            return sbConnection.ToString();

        }
开发者ID:tojoirinah,项目名称:Refonte-Recueil-One,代码行数:20,代码来源:ImportHelper.cs

示例9: GetCSVStringConnection

        private string GetCSVStringConnection(string fullFileName)
        {
            OleDbConnectionStringBuilder sbConnection = new OleDbConnectionStringBuilder();
            String strExtendedProperties = String.Empty;
            sbConnection.DataSource = fullFileName;
            sbConnection.Provider = "Microsoft.ACE.OLEDB.12.0";
            strExtendedProperties = "Text;HDR=YES;FMT=Delimited";

            sbConnection.Add("Extended Properties", strExtendedProperties);

            return sbConnection.ToString();

        }
开发者ID:tojoirinah,项目名称:Refonte-Recueil-One,代码行数:13,代码来源:ImportHelper.cs

示例10: GetNativeConnection

        protected override OleDbConnection GetNativeConnection(string connectionString)
        {
            OleDbConnectionStringBuilder oleDBCnnStrBuilder = new OleDbConnectionStringBuilder(connectionString);
            oleDBCnnStrBuilder.Provider = "Microsoft.ACE.OLEDB.12.0";

            return new OleDbConnection(oleDBCnnStrBuilder.ToString());
        }
开发者ID:NALSS,项目名称:epiinfo-82474,代码行数:7,代码来源:Access2007Database.cs

示例11: Main

        static void Main(string[] args)
        {
            // read in arguments, parse them for easy consumption
            ParseCommandlineArguments(args);

            // setup log processor
            _logFileProcessor = LogFileProcessor.Create(_type);
            _logFileProcessor.LogFiles = _logs.GetFiles(_logFilter);

            // set up logger
            Logger.DiskLog = _executionLog;

            // Print welcome message
            Logger.Info();
            Logger.Info(" ##################################################");
            Logger.Info(" # Apatche Log Files to Access Database Converter #");
            Logger.Info(" #                                                #");
            Logger.Info(" # Version 0.3                                    #");
            Logger.Info(" # By: Egil Hansen (http://egilhansen.com)        #");
            Logger.Info(" ##################################################");
            Logger.Info();
            Logger.Info("Runtime settings:");
            Logger.Info();
            Console.ForegroundColor = ConsoleColor.DarkBlue;
            Logger.Info("  Database File (db) ................... : {0}", _dbFileName.FullName);
            Logger.Info("  Overwrite Existing DB File (overwrite) : {0}", _overwrite.ToString());
            Logger.Info("  Logs Directory (logs) ................ : {0}", _logs.FullName);
            Logger.Info("  Log filter (filter) .................. : {0}", _logFilter);
            Logger.Info("  Log File Type (type) ................. : {0}", _logFileProcessor.Name);
            Logger.Info("  Runetime Log (runtimelog) ............ : {0}", _executionLog != null ? _executionLog.FullName : "n/a");
            Logger.Info();
            Console.ResetColor();

            // create target database based on log file type
            var csb = new OleDbConnectionStringBuilder { DataSource = _dbFileName.FullName, Provider = "Microsoft.Jet.OLEDB.4.0" };

            // remove existing database file
            if (_dbFileName.Exists && _overwrite)
            {
                _dbFileName.Delete();
            }

            // create database
            if (_dbFileName.Exists)
            {
                AddTable(csb);
            }
            else
            {
                CreateAccessDatabase(csb.ToString());
            }

            // parse each log file, add each log entry to database
            Logger.Info("Starting log file processing . . .");
            Logger.LogOffscreen(string.Empty);
            Logger.LogOffscreen("Start time: {0}", DateTime.Now);
            Logger.Info();

            _logFileProcessor.Process(csb.ToString());
        }
开发者ID:egil,项目名称:alfac,代码行数:60,代码来源:Program.cs

示例12: BuildConnectionString

        /// <summary>
        /// Gets table schema information about an OLE database
        /// </summary>
        /// <returns>DataTable with schema information</returns>
        //This function has been fixed in parent class, It should work for all database type  //  zack 1/30/08
        //public override DataTable GetTableSchema()
        //{
        //DataTable schema = base.GetSchema("Tables");
        //foreach (DataRow row in schema.Rows)
        //{
        //    // TODO: This isn't asbolute, should be replaced with search on...
        //    // exact system table names
        //    if (row[ColumnNames.SCHEMA_TABLE_NAME].ToString().StartsWith("MSys", true, CultureInfo.InvariantCulture))
        //    {
        //        row.Delete();
        //    }
        //}
        //schema.AcceptChanges();
        //    return schema;
        //}
        public static string BuildConnectionString(string filePath, string password)
        {
            StringBuilder builder = new StringBuilder();

            if (filePath.EndsWith(".accdb", true, System.Globalization.CultureInfo.InvariantCulture))
            {
                builder.Append("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=");
            }

            builder.Append(EncodeOleDbConnectionStringValue(filePath));
            builder.Append(";");

            builder.Append("User Id=admin;Password=;");

            if (!string.IsNullOrEmpty(password))
            {
                builder.Append("Jet OLEDB:Database Password=");
                builder.Append(EncodeOleDbConnectionStringValue(password));
                builder.Append(";");
            }

            // sanity check
            OleDbConnectionStringBuilder connectionBuilder = new OleDbConnectionStringBuilder(builder.ToString());
            return connectionBuilder.ToString();
        }
开发者ID:NALSS,项目名称:epiinfo-82474,代码行数:45,代码来源:Access2007Database.cs

示例13: ProcessConnectionString

        /// <summary>
        /// Extracts file location and replaces relative file paths with full file paths by updating ConnectionString value
        /// </summary>
        protected void ProcessConnectionString()
        {
            this.location = null;
            if (this.connectionString == null) return;

            OleDbConnectionStringBuilder builder = new OleDbConnectionStringBuilder(this.connectionString);

            string filename = builder.DataSource;
            if (File.Exists(filename))
            {
                if (!Path.IsPathRooted(filename))
                {
                    filename = Path.GetFullPath(filename);
                }
                this.location = filename;
                this.DbName = Path.GetFileNameWithoutExtension(this.location);
                this.connectionString = builder.ToString();
            }
        }
开发者ID:NALSS,项目名称:epiinfo-82474,代码行数:22,代码来源:OleDbDatabase.cs

示例14: loadExcelFile

        private DataTable loadExcelFile(string fileName, string sheetName)
        {
            OleDbConnection objConn = null;
            OleDbConnectionStringBuilder sbConnection = new OleDbConnectionStringBuilder();
            sbConnection.DataSource = fileName;
            String strExtendedProperties = Path.GetExtension(fileName);
            try
            {
               DataTable table = new DataTable();
               if (Path.GetExtension(fileName).Equals(".xls"))//for 97-03 Excel file
                  {
                      sbConnection.Provider = "Microsoft.Jet.OLEDB.4.0";
                      strExtendedProperties = "Excel 8.0;HDR=Yes;IMEX=1";//HDR=ColumnHeader,IMEX=InterMixed
                  }
                  else if (Path.GetExtension(fileName).Equals(".xlsx"))  //for 2007 Excel file
                  {
                      sbConnection.Provider = "Microsoft.ACE.OLEDB.12.0";
                      strExtendedProperties = "Excel 12.0;HDR=Yes;IMEX=1";
                  }
                  sbConnection.Add("Extended Properties", strExtendedProperties);
                  objConn = new OleDbConnection(sbConnection.ToString());
                  objConn.Open();
                  using (OleDbDataAdapter dbAdapter = new OleDbDataAdapter("SELECT * FROM [" + sheetName + "]", objConn)) //rename sheet if required!
                      dbAdapter.Fill(table);

                if (table == null)
                {
                    return null;
                }
                creator.loadData(table);
                return table;
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                // Clean up.
                if (objConn != null)
                {
                    objConn.Close();
                    objConn.Dispose();
                }
                if (dt != null)
                {
                    dt.Dispose();
                }
            }
        }
开发者ID:EmperorShmoo,项目名称:Project,代码行数:50,代码来源:SheetSelect.cs

示例15: SheetNames

        private String[] SheetNames(string fileName)
        {
            String[] Sheets = null;
            OleDbConnection objConn = null;
            OleDbConnectionStringBuilder sbConnection = new OleDbConnectionStringBuilder();
            sbConnection.DataSource = fileName;
            String strExtendedProperties = Path.GetExtension(fileName);
            try
            {
                if (Path.GetExtension(fileName).Equals(".xls") || Path.GetExtension(fileName).Equals(".xlsx"))//any excel sheet
                {
                    if (Path.GetExtension(fileName).Equals(".xls"))//for 97-03 Excel file
                    {
                        sbConnection.Provider = "Microsoft.Jet.OLEDB.4.0";
                        strExtendedProperties = "Excel 8.0;HDR=Yes;IMEX=1";//HDR=ColumnHeader,IMEX=InterMixed
                    }
                    else if (Path.GetExtension(fileName).Equals(".xlsx"))  //for 2007 Excel file
                    {
                        sbConnection.Provider = "Microsoft.ACE.OLEDB.12.0";
                        strExtendedProperties = "Excel 12.0;HDR=Yes;IMEX=1";
                    }
                    sbConnection.Add("Extended Properties", strExtendedProperties);
                    objConn = new OleDbConnection(sbConnection.ToString());
                    objConn.Open();
                    dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

                    if (dt == null)
                    {
                        return null;
                    }

                    Sheets = new String[dt.Rows.Count];
                    int i = 0;

                    // Add the sheet name to the string array.
                    foreach (DataRow row in dt.Rows)
                    {
                        if (row["TABLE_NAME"].ToString().Contains("$")
                            && !row["TABLE_NAME"].ToString().Contains("$Print")
                            && !row["TABLE_NAME"].ToString().Contains("$'Print")
                             && !row["TABLE_NAME"].ToString().Contains("$_"))//checks whether row contains '_xlnm#_FilterDatabase' or sheet name(i.e. sheet name always ends with $ sign)
                        {
                            Sheets[i] = row["TABLE_NAME"].ToString();
                            //Sheets[i] = Sheets[i].Replace("$", "");
                            //Sheets[i] = Sheets[i].Replace("'", "");
                            i++;
                        }
                    }
                }
                return Sheets;
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                // Clean up.
                if (objConn != null)
                {
                    objConn.Close();
                    objConn.Dispose();
                }
                if (dt != null)
                {
                    dt.Dispose();
                }
            }
        }
开发者ID:EmperorShmoo,项目名称:Project,代码行数:69,代码来源:SheetSelect.cs


注:本文中的System.Data.OleDb.OleDbConnectionStringBuilder.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。