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


C# SqlDataReader.GetFieldType方法代码示例

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


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

示例1: ConvertdrTodt

        /// <summary>
        /// 将DataReader转为DataTable
        /// </summary>
        /// <param name="DataReader">DataReader</param>
        public static DataTable ConvertdrTodt(SqlDataReader dataReader)
        {
            ///定义DataTable
            DataTable datatable = new DataTable();

            ///动态添加表的数据列
            for (int i = 0; i < dataReader.FieldCount; i++)
            {
                DataColumn mydc = new DataColumn();
                mydc.DataType = dataReader.GetFieldType(i);
                mydc.ColumnName = dataReader.GetName(i);
                datatable.Columns.Add(mydc);
            }

            ///添加表的数据
            while (dataReader.Read())
            {
                DataRow mydr = datatable.NewRow();
                for (int i = 0; i < dataReader.FieldCount; i++)
                {
                    mydr[i] = dataReader[i].ToString();
                }
                datatable.Rows.Add(mydr);
                mydr = null;
            }
            ///关闭数据读取器
            dataReader.Close();
            return datatable;
        }
开发者ID:SaintLoong,项目名称:LayerDemo,代码行数:33,代码来源:SqlHelperOther.cs

示例2: Convertdrtodt

        /// <summary>
        /// SqlDataReaderתDataTableTable
        /// </summary>
        /// <param name="dr"></param>
        /// <returns></returns>
        public static DataTable Convertdrtodt(SqlDataReader dr, DataTable dataTable)
        {
            //DataTable dataTable = new DataTable();//��һ���µ�ʵ��

            for (int i = 0; i < dr.FieldCount; i++)
            {
                DataColumn mydc = new DataColumn();//�ؼ���һ��
                mydc.DataType = dr.GetFieldType(i);
                mydc.ColumnName = dr.GetName(i);

                dataTable.Columns.Add(mydc);//�ؼ��ĵڶ���
            }

            while (dr.Read())
            {
                DataRow mydr = dataTable.NewRow();//�ؼ��ĵ�����
                for (int i = 0; i < dr.FieldCount; i++)
                {
                    mydr[i] = dr[i];//.ToString();
                }

                dataTable.Rows.Add(mydr);//�ؼ��ĵ��IJ�
                mydr = null;
            }

            dr.Close();
            return (dataTable);//������Ҫ����datatable���������
        }
开发者ID:dalinhuang,项目名称:qqhelp-heimu360,代码行数:33,代码来源:SQLExecute.cs

示例3: CreateSchemaFromReader

        // Метод формирования DataTable с именем tableName из SqlDataReader
        private static DataTable CreateSchemaFromReader(SqlDataReader reader, string tableName)
        {
            DataTable table = new DataTable(tableName);
            // Добавление в таблицу нового столбца (Имя - Тип )
            for (int i = 0; i < reader.FieldCount; i++)
                table.Columns.Add(new DataColumn(reader.GetName(i), reader.GetFieldType(i)));

            return table;
        }
开发者ID:Saroko-dnd,项目名称:My_DZ,代码行数:10,代码来源:Program.cs

示例4: SqlDataHelper

 public SqlDataHelper(SqlDataReader reader)
 {
     _reader=reader;
     if (_cnames == null)
     {
         _cnames = new string[_reader.FieldCount];
         _cdbtypes = new string[_reader.FieldCount];
         _ctypes = new Type[_reader.FieldCount];
         for (int i = 0; i < _reader.FieldCount; i++)
         {
             _cdbtypes[i] = _reader.GetDataTypeName(i);
             _ctypes[i] = _reader.GetFieldType(i);
             _cnames[i] = _reader.GetName(i);
         }
     }
 }
开发者ID:neilberg,项目名称:rsqlserver,代码行数:16,代码来源:SqlDataHelper.cs

示例5: CreateObject

        public static string CreateObject(SqlDataReader sdr, string objectName, bool camelCase)
        {
            if (sdr == null || !sdr.HasRows) return string.Empty;

            System.Text.StringBuilder js = new System.Text.StringBuilder("var " + objectName + " = [");
            string[] names = JSOMembers(sdr, camelCase);

            while (sdr.Read())
            {
                js.Append("\n{");
                for (int i = 0; i < sdr.FieldCount; i++)
                {
                    // Response.Write(sdr.GetFieldType(i).Name.ToLower() + "\n");
                    switch (sdr.GetFieldType(i).Name.ToLower())
                    {
                        case "int":
                        case "byte":
                        case "long":
                        case "short":
                        case "decimal":
                        case "double":
                            js.Append(names[i] + ": " + sdr[i].ToString());
                            break;
                        case "boolean":
                            js.Append(names[i] + ": " + sdr.GetBoolean(i).ToString().ToLower());
                            break;
                        default:
                            js.Append(names[i] + ": '" + sdr[i].ToString() + "'");
                            break;
                    }
                    if ((i + 1) < sdr.FieldCount)
                        js.Append(',');
                }
                js.Append("},");
            }
            js[js.Length - 1] = ']';
            js.Append(';');
            return js.ToString();
        }
开发者ID:varunkho,项目名称:Akshar,代码行数:39,代码来源:JS.cs

示例6: ConvertDataReaderToDataTable

        /// <summary>
        /// ��DataReaderתΪDataTable
        /// </summary>
        /// <param name="DataReader">DataReader</param>
        public static DataTable ConvertDataReaderToDataTable(SqlDataReader dataReader)
        {
            ///����DataTable
            DataTable datatable = new DataTable();

            try
            {	///��̬��ӱ��������
                for(int i = 0; i < dataReader.FieldCount; i++)
                {
                    DataColumn myDataColumn = new DataColumn();
                    myDataColumn.DataType = dataReader.GetFieldType(i);
                    myDataColumn.ColumnName = dataReader.GetName(i);
                    datatable.Columns.Add(myDataColumn);
                }

                ///��ӱ������
                while (dataReader.Read())
                {
                    DataRow myDataRow = datatable.NewRow();
                    for (int i = 0; i < dataReader.FieldCount; i++)
                    {
                        myDataRow[i] = dataReader[i].ToString();
                    }
                    datatable.Rows.Add(myDataRow);
                    myDataRow = null;
                }
                ///�ر����ݶ�ȡ��
                dataReader.Close();
                return datatable;
            }
            catch(Exception ex)
            {
                ///�׳�����ת������
                SystemError.CreateErrorLog(ex.Message);
                throw new Exception(ex.Message,ex);
            }
        }
开发者ID:conghuiw,项目名称:exam-report,代码行数:41,代码来源:SystemTools.cs

示例7: TomarValorJSON

 /// <summary>
 /// Convierte un valor en un SqlDataReader a JSON para ser incluido en un JSN array
 /// </summary>
 /// <param name="Lector">Referencia hacia al lector (SqlDataReader)</param>
 /// <param name="Puntero">Puntero del valor a convertir dentro del lector (SqlDataReader)</param>
 /// <returns>Valor para un objeto JSON</returns>
 private string TomarValorJSON(ref SqlDataReader Lector,ref short Puntero)
 {
     return string.Format(
                         "\"{0}\":{1}",
                         Lector.GetName(Puntero),
                         (Lector.IsDBNull(Puntero)) ? "null" :
                             ((Lector.GetFieldType(Puntero) == typeof(bool) || Lector.GetFieldType(Puntero) == typeof(Boolean)) ?
                                 ((Lector.GetFieldValue<bool>(Puntero)) ? "true" : "false") :
                                 ((Lector.GetFieldType(Puntero) == typeof(int) || Lector.GetFieldType(Puntero) == typeof(byte)
                                 || Lector.GetFieldType(Puntero) == typeof(Int16) || Lector.GetFieldType(Puntero) == typeof(float)
                                 || Lector.GetFieldType(Puntero) == typeof(double)) || Lector.GetFieldType(Puntero) == typeof(decimal) ?
                                 Lector.GetFieldValue<object>(Puntero) :
                                 (Lector.GetFieldType(Puntero) == typeof(DateTime) ? UnixTicks(Lector.GetDateTime(Puntero)) :
                                 "\"" + Lector.GetFieldValue<object>(Puntero)
                                 .ToString()
                                 .Replace("\n", "<br>")
                         //.Replace("\t", "\\\\u09")
                         .Replace("\r", "<br>")
                         //.Replace("\\", "\\\\u2f")
                         //.Replace("'", "\\\\u27")
                         .Replace("\"", "\\\\u22")
                         //.Replace("{", "\\\\u7b")
                         //.Replace("}", "\\\\u7e")
                         //.Replace("[", "\\\\u5b")
                         //.Replace("]", "\\\\u5d")
                         //.Replace(":", "\\\\u3a")
                         + "\""))
                                 )
                         )
                         ;
 }
开发者ID:yorb1990,项目名称:WebAPISQL,代码行数:37,代码来源:JSON.cs

示例8: GetConvertDataReaderToDataTable

        /// <summary> 
        /// DataReader格式转换成DataTable 
        /// </summary> 
        /// <param name="DataReader">OleDbDataReader</param> 
        private DataTable GetConvertDataReaderToDataTable(SqlDataReader reader)
        {
            DataTable objDataTable = new DataTable("TmpDataTable");
            int intCounter;

            try
            {
                //获取当前行中的列数;
                int intFieldCount = reader.FieldCount;

                for (intCounter = 0; intCounter <= intFieldCount - 1; intCounter++)
                {
                    objDataTable.Columns.Add(reader.GetName(intCounter), reader.GetFieldType(intCounter));
                }

                //populate   datatable   
                objDataTable.BeginLoadData();

                //object[]   objValues   =   new   object[intFieldCount   -1];   
                object[] objValues = new object[intFieldCount];

                while (reader.Read())
                {
                    reader.GetValues(objValues);
                    objDataTable.LoadDataRow(objValues, true);
                }
                reader.Close();

                objDataTable.EndLoadData();

                return objDataTable;

            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
开发者ID:xlgwr,项目名称:producting,代码行数:42,代码来源:CSQLServerConnect.cs

示例9: getFieldValue

 public static System.DateTime getFieldValue(SqlDataReader dr, int ind, System.DateTime def)
 {
     System.DateTime val = def;
     if (!dr.IsDBNull(ind))
     {
         System.TypeCode tp = System.Type.GetTypeCode(dr.GetFieldType(ind));
         System.TypeCode typeCode = tp;
         switch (typeCode)
         {
             case System.TypeCode.Byte:
                 val = System.Convert.ToDateTime(dr.GetByte(ind));
                 break;
             case System.TypeCode.Int16:
                 val = System.Convert.ToDateTime(dr.GetInt16(ind));
                 break;
             case System.TypeCode.UInt16:
                 break;
             case System.TypeCode.Int32:
                 val = System.Convert.ToDateTime(dr.GetInt32(ind));
                 break;
             default:
                 if (typeCode == System.TypeCode.DateTime)
                 {
                     val = dr.GetDateTime(ind);
                 }
                 break;
         }
     }
     return val;
 }
开发者ID:ranyaof,项目名称:gismaster,代码行数:30,代码来源:DBManagerSQL.cs

示例10: Build

        public static BsonDocument Build(SqlDataReader dr)
        {
            BsonDocument bsonDocument = new BsonDocument();

            for(int i=0; i<dr.FieldCount; i++)
            {
                Type propertyType = dr.GetFieldType(i);
                if (dr.GetName(i) == "ObjectId")
                {
                    WriteObjectId(dr, i, bsonDocument);
                }
                else if (dr.GetName(i) == "Timestamp")
                {
                    WriteTimestamp(dr, i, bsonDocument);
                }
                else if (dr.GetName(i) == "ReportNo")
                {
                    WriteReportNo(dr, i, bsonDocument);
                }
                else if (dr.GetName(i) == "PanelOrderId")
                {
                    WriteReportNo(dr, i, bsonDocument);
                }
                else if (propertyType == typeof(string))
                {
                    WriteString(dr, i, bsonDocument);
                }
                else if (propertyType == typeof(int))
                {
                    WriteInt(dr, i, bsonDocument);
                }
                else if (propertyType == typeof(double))
                {
                    WriteDouble(dr, i, bsonDocument);
                }
                else if (propertyType == typeof(decimal))
                {
                    WriteDouble(dr, i, bsonDocument);
                }
                else if (propertyType == typeof(Nullable<int>))
                {
                    WriteInt(dr, i, bsonDocument);
                }
                else if (propertyType == typeof(DateTime))
                {
                    WriteDateTime(dr, i, bsonDocument);
                }
                else if (propertyType == typeof(bool))
                {
                    WriteBoolean(dr, i, bsonDocument);
                }
                else if (propertyType == typeof(Nullable<bool>))
                {
                    WriteBoolean(dr, i, bsonDocument);
                }
                else if (propertyType == typeof(Nullable<DateTime>))
                {
                    WriteDateTime(dr, i, bsonDocument);
                }
                else
                {
                    throw new Exception("This Data Type is Not Implemented: " + dr.GetFieldType(i).ToString() + ": " + dr.GetName(i));
                }
            }

            return bsonDocument;
        }
开发者ID:WilliamCopland,项目名称:YPILIS,代码行数:67,代码来源:BSONDRBuilder.cs

示例11: PengecekField

        // Jika tidak menggunakan constructor
        // hapus pada baris yg di comment
        // ====================================
        // | Alt + Insert untuk meng-generate |
        // | construktor dari class yg dibuat |
        // ====================================
        public string PengecekField(SqlDataReader hasilPembaca, byte kolom)
        {
            string hasil = "";
            if (hasilPembaca.IsDBNull(kolom))
            {
                if (hasilPembaca.GetFieldType(kolom).ToString().Trim() == "System.Byte")
                    hasil = "0";
                else if (hasilPembaca.GetFieldType(kolom).ToString().Trim() == "System.Boolean")
                    hasil = "false";
                else if (hasilPembaca.GetFieldType(kolom).ToString().Trim() == "System.Int32")
                    hasil = "0";
                else if (hasilPembaca.GetFieldType(kolom).ToString().Trim() == "System.Int16")
                    hasil = "0";
                else if (hasilPembaca.GetFieldType(kolom).ToString().Trim() == "System.String")
                    hasil = "";
                else if (hasilPembaca.GetFieldType(kolom).ToString().Trim() == "System.Decimal")
                    hasil = "0";
                else if (hasilPembaca.GetFieldType(kolom).ToString().Trim() == "System.Int64")
                    hasil = "0";
                else if (hasilPembaca.GetFieldType(kolom).ToString().Trim() == "System.DateTime")
                    hasil = "0";
                else
                {
                    MessageBox.Show(Resources.CAlat_PengecekField_Tipe_data_tidak_di_kenali, Resources.CAlat_PengecekField_Infomasi, MessageBoxButtons.OK,
                        MessageBoxIcon.Information);
                }
            }
            else
            {
                if (hasilPembaca.GetFieldType(kolom).ToString().Trim() == "System.Byte")
                    hasil = hasilPembaca.GetByte(kolom).ToString().Trim();
                else if (hasilPembaca.GetFieldType(kolom).ToString().Trim() == "System.Boolean")
                    hasil = hasilPembaca.GetBoolean(kolom).ToString().Trim();
                else if (hasilPembaca.GetFieldType(kolom).ToString().Trim() == "System.Int32")
                    hasil = hasilPembaca.GetInt32(kolom).ToString().Trim();
                else if (hasilPembaca.GetFieldType(kolom).ToString().Trim() == "System.Int16")
                    hasil = hasilPembaca.GetInt16(kolom).ToString().Trim();
                else if (hasilPembaca.GetFieldType(kolom).ToString().Trim() == "System.String")
                    hasil = hasilPembaca.GetString(kolom).ToString().Trim();
                else if (hasilPembaca.GetFieldType(kolom).ToString().Trim() == "System.Decimal")
                    hasil = hasilPembaca.GetDecimal(kolom).ToString().Trim();
                else if (hasilPembaca.GetFieldType(kolom).ToString().Trim() == "System.Int64")
                    hasil = hasilPembaca.GetInt64(kolom).ToString().Trim();
                else if (hasilPembaca.GetFieldType(kolom).ToString().Trim() == "System.DateTime")
                    hasil = string.Format("{0:MM/dd/yyyy}", hasilPembaca.GetDateTime(kolom));
                else
                {
                    MessageBox.Show(Resources.CAlat_PengecekField_Tipe_data_tidak_di_kenali, Resources.CAlat_PengecekField_Infomasi, MessageBoxButtons.OK,
                        MessageBoxIcon.Information);
                }
            }

            return hasil;
        }
开发者ID:nasi-be-guling,项目名称:realanggar,代码行数:60,代码来源:cAlat.cs

示例12: ConstructData

		/// <summary>
		/// Constructs the data which was extracted from the database according to user's query.
		/// </summary>
		/// <param name="reader">SqlReader - holds the queried data.</param>
		///<returns>Queried data in DataTable.</returns>
		private static DataTable ConstructData(SqlDataReader reader)
		{
			try
			{
				if(reader.IsClosed)
					throw new InvalidOperationException("Attempt to use a closed SqlDataReader");
				
				DataTable dataTable = new DataTable();
			
				// constructs the columns data.
				for(int i=0; i<reader.FieldCount; i++)
					dataTable.Columns.Add(reader.GetName(i), reader.GetFieldType(i));

				// constructs the table's data.
				while(reader.Read())
				{	
					object[] row = new object[reader.FieldCount];
					reader.GetValues(row);
					dataTable.Rows.Add(row);
				}
				// Culture info.
				dataTable.Locale = CultureInfo.InvariantCulture;
				// Accepts changes.
				dataTable.AcceptChanges();
				
				return dataTable;
			}
			catch(Exception e)
			{
				Log.WriteErrorToLog(e.Message);
				throw;
			}
		}
开发者ID:ViniciusConsultor,项目名称:ecustomsgs1,代码行数:38,代码来源:SqlAccessor.cs

示例13: GetInt64

    long GetInt64(SqlDataReader reader, int colnum) {
        // For some reason, it won't just up-convert int32 to int64
        if (reader.GetFieldType(colnum) == typeof(System.Int32)) {
            return reader.GetInt32(colnum);
        } else if (reader.GetFieldType(colnum) == typeof(System.Int64)) {
            return reader.GetInt64(colnum);
        } else if (reader.GetFieldType(colnum) == typeof(System.Decimal)) {
            return (long)reader.GetDecimal(colnum);
        } else {
            // Unknown type
            bool unknown_type_in_result = true;
            WVFAIL(unknown_type_in_result);

            return -1;
        }
    }
开发者ID:apenwarr,项目名称:versaplex,代码行数:16,代码来源:sqlsucker.test.cs

示例14: ReplaceTemplate

 public static StringBuilder ReplaceTemplate(SqlDataReader sdr, StringBuilder template, bool IsRemoveNoData)
 {
     DataTable dt = new DataTable();
     int fcnt=sdr.FieldCount;
     for (int i = 0; i < fcnt; i++)
     {
         dt.Columns.Add(new DataColumn(sdr.GetName(i),sdr.GetFieldType(i)));
     }
     DataRow row = dt.NewRow();
     object[] Values = new object[fcnt];
     sdr.GetValues(Values);
     row.ItemArray = Values;
     return ReplaceTemplate(row, template, IsRemoveNoData);
 }
开发者ID:lakeli,项目名称:shizong,代码行数:14,代码来源:Template.cs

示例15: CheckAndReturnValue

        private static List<Dictionary<string, object>> CheckAndReturnValue(SqlDataReader reader)
        {
            //     Change History
            //
            //      Date        Edit    Author      Comment
            //   -----------+-------+-------+---------------------------------------------
            //     02-Feb-12    [100]    SSN        Created
            //   -----------+-------+-------+---------------------------------------------

            object obj;
            int Ordinal = 0;
            obj = null;
            List<Dictionary<string, object>> results = new List<Dictionary<string, object>>();
            Dictionary<string, object> ColValues;
            while (reader.Read())
            {
                ColValues = new Dictionary<string, object>();
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    if (reader.GetFieldType(i) == Type.GetType("System.String"))
                    {
                        obj = reader.IsDBNull(i) ? String.Empty : reader.GetValue(i);
                    }
                    else if (reader.GetFieldType(i) == Type.GetType("System.Decimal"))
                    {
                        obj = reader.IsDBNull(i) ? 0 : reader.GetValue(i);
                    }
                    else if (reader.GetFieldType(i) == Type.GetType("System.DateTime"))
                    {
                        obj = reader.IsDBNull(i) ? new DateTime() : reader.GetDateTime(i);
                    }
                    else
                    {
                        obj = reader.IsDBNull(Ordinal) ? null : reader.GetValue(i);
                    }
                    ColValues.Add(reader.GetName(i).ToUpper(), obj);
                }
                results.Add(ColValues);
            }
            return results;
        }
开发者ID:srikhs,项目名称:savvy12,代码行数:41,代码来源:Common.cs


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