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


C# ADODB.Recordset.GetString方法代码示例

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


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

示例1: CopyTable

        public void CopyTable(ADOX.Table tblAccess)
        {
            ADODB.Recordset recMaster = new ADODB.Recordset();
            ADODB.Recordset recLoop = new ADODB.Recordset();
            int intLoop = 0;

            string strInfile = "";
            string strSQL = "SELECT ";
            string strRecord;
            string strLoadFilePath = strSourceDbPath.Replace("\\", "\\\\");
            string strFileName = strTempPath + tblAccess.Name + ".txt";

            StreamWriter sw = new StreamWriter(strFileName, false);
            //create the infile
                strInfile += "LOAD DATA LOCAL INFILE '" + strFileName + "' INTO TABLE " + strMySQLDBName + "." + tblAccess.Name + " ";
                strInfile += "FIELDS TERMINATED BY ',' ";
                strInfile += "ESCAPED BY '\\\\' ";
                strInfile += "LINES TERMINATED BY 0x0d0a ";
                strInfile += "(";

                //loop through fields to enumerate them for the infile and build a select statement
                for (intLoop = 0; intLoop < tblAccess.Columns.Count; intLoop++)
                {
                    strInfile += MySQLName((tblAccess.Columns[intLoop].Name));
                    switch (tblAccess.Columns[intLoop].Type)
                    {
                        case ADOX.DataTypeEnum.adDate: //convert to MySQL datetime format
                            strSQL += "FORMAT([" + tblAccess.Columns[intLoop].Name + "],  'YYYY-MM-DD HH:MM:SS') as " + tblAccess.Columns[intLoop].Name;
                            break;
                        default:
                            strSQL += "[" + tblAccess.Columns[intLoop].Name + "]";
                            break;
                    }
                    if (intLoop < tblAccess.Columns.Count - 1)
                    {
                        strSQL += ",";
                        strInfile += ", ";
                    }
                }
                strInfile += ");";
                strSQL += " FROM [" + tblAccess.Name + "]";

                //open the "Master" recordset
                recMaster.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
                recMaster.Open(strSQL, conJCMS_db, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic, 0);

                //create the "Loop" recordset, this is a clone of the master, with the exception
                //that the definedsize for text fields is lengthened.  This is because the added
                //escape characters could potentially exceed the field length in the master recordset
                recLoop.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
                ADODB.Fields fdsLoop = recLoop.Fields;
                ADODB.Fields fdsMaster = recMaster.Fields;
                foreach (ADODB.Field fldIn in fdsMaster)
                {
                    if (fldIn.Type.ToString().IndexOf("Char") > 0)
                    {
                        fdsLoop.Append(fldIn.Name,
                            fldIn.Type,
                            fldIn.DefinedSize + 30,
                            ADODB.FieldAttributeEnum.adFldIsNullable,
                            null);
                    }
                    else
                    {
                        fdsLoop.Append(fldIn.Name,
                        fldIn.Type,
                        fldIn.DefinedSize,
                        ADODB.FieldAttributeEnum.adFldIsNullable,
                        null);
                    }
                }
                recLoop.Open(System.Reflection.Missing.Value, System.Reflection.Missing.Value, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic, 0);

                recLoop.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);

                while (!recMaster.EOF)
                {
                    for (int columnIndex = 0; columnIndex < recMaster.Fields.Count; columnIndex++)
                    {
                        recLoop.Fields[columnIndex].Value = recMaster.Fields[columnIndex].Value;
                        if (recLoop.Fields[columnIndex].Value.ToString().Length > 0)
                        {
                            if ((recLoop.Fields[columnIndex].Value.ToString().IndexOf("\\", 0) + 1) > 0)
                            {
                                recLoop.Fields[columnIndex].Value = recLoop.Fields[columnIndex].Value.ToString().Replace("\\", "\\\\");
                            }
                            if ((recLoop.Fields[columnIndex].Value.ToString().IndexOf(",", 0) + 1) > 0)
                            {
                                recLoop.Fields[columnIndex].Value = recLoop.Fields[columnIndex].Value.ToString().Replace(",", "\\,");
                            }
                            if ((recLoop.Fields[columnIndex].Value.ToString().IndexOf(System.Environment.NewLine, 0) + 1) > 0)
                            {
                                recLoop.Fields[columnIndex].Value = recLoop.Fields[columnIndex].Value.ToString().Replace(System.Environment.NewLine, " ");
                            }
                        }
                    }
                    strRecord = recLoop.GetString(ADODB.StringFormatEnum.adClipString, 1, ",", System.Environment.NewLine, "\\N");
                    recLoop.MovePrevious();
                    sw.Write(strRecord);
                    recMaster.MoveNext();
//.........这里部分代码省略.........
开发者ID:BethSundberg,项目名称:JCMS-root,代码行数:101,代码来源:frmProgress.cs


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