本文整理汇总了C#中MySql.Data.MySqlClient.MySqlDataReader.GetFieldType方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlDataReader.GetFieldType方法的具体用法?C# MySqlDataReader.GetFieldType怎么用?C# MySqlDataReader.GetFieldType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySql.Data.MySqlClient.MySqlDataReader
的用法示例。
在下文中一共展示了MySqlDataReader.GetFieldType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DBColumnToPyObject
public static PyObject DBColumnToPyObject(int index, ref MySqlDataReader reader)
{
Type type = reader.GetFieldType(index);
switch (type.Name)
{
case "String":
return new PyString(reader.GetString(index));
case "UInt32":
case "Int32":
case "UInt16":
case "Int16":
case "SByte":
case "Byte":
return new PyInt(reader.GetInt32(index));
case "UInt64":
case "Int64":
return new PyLongLong(reader.GetInt64(index));
case "Byte[]":
return new PyBuffer((byte[])reader.GetValue(index));
case "Double":
return new PyFloat(reader.GetDouble(index));
case "Decimal":
return new PyFloat((double)reader.GetDecimal(index));
case "Boolean":
return new PyBool(reader.GetBoolean(index));
default:
Log.Error("Database", "Unhandled MySQL type " + type.Name);
break;
}
return null;
}
示例2: GetSchemaFromReader
/// <summary>
/// Gets CRUD schema from MySqlReader per particular QuerySource.
/// If source is null then all columns from reader are copied.
/// Note: this code was purposely made provider specific because other providers may treat some nuances differently
/// </summary>
public static Schema GetSchemaFromReader(string name, QuerySource source, MySqlDataReader reader)
{
var table = name;
var fdefs = new List<Schema.FieldDef>();
for (int i = 0; i < reader.FieldCount; i++)
{
var fname = reader.GetName(i);
var ftype = reader.GetFieldType(i);
var def = new Schema.FieldDef(fname, ftype, source!=null ? ( source.HasPragma ? source.ColumnDefs[fname] : null) : null);
fdefs.Add( def );
}
if (source!=null)
if (source.HasPragma && source.ModifyTarget.IsNotNullOrWhiteSpace()) table = source.ModifyTarget;
if (table.IsNullOrWhiteSpace()) table = Guid.NewGuid().ToString();
return new Schema(table, source!=null ? source.ReadOnly : true, fdefs);
}
示例3: GetType
public FieldType GetType(int index, ref MySqlDataReader reader)
{
Type type = reader.GetFieldType(index);
switch (type.Name)
{
case "String":
return FieldType.Str;
case "UInt32":
return FieldType.UI4;
case "Int32":
return FieldType.I4;
case "UInt16":
return FieldType.UI2;
case "Int16":
return FieldType.I2;
case "UInt64":
return FieldType.UI8;
case "Int64":
return FieldType.I8;
case "Byte[]":
return FieldType.Bytes;
case "SByte":
return FieldType.I1; ;
case "Double":
return FieldType.R8;
case "Decimal":
return FieldType.R4;
case "Boolean":
return FieldType.Bool;
case "Byte":
return FieldType.UI1;
default:
throw new Exception("Wrong FieldType");
}
}
示例4: GetConvertDataReaderToDataTable
/// <summary>
/// DataReader格式转换成DataTable
/// </summary>
/// <param name="DataReader">OleDbDataReader</param>
private DataTable GetConvertDataReaderToDataTable(MySqlDataReader 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 (MySqlException ex)
{
throw ex;
}
}