MySql.Data.MySqlClient.MySqlDataReader.GetFieldType C# (CSharp) Method

GetFieldType() public method

Gets the Type that is the data type of the object.
public GetFieldType ( int i ) : Type
i int
return System.Type
    public override Type GetFieldType(int i)
    {
      if (!isOpen)
        Throw(new Exception("No current query in data reader"));
      if (i >= FieldCount)
        Throw(new IndexOutOfRangeException());

      // we have to use the values array directly because we can't go through
      // GetValue
      IMySqlValue v = resultSet.Values[i];
      if (v is MySqlDateTime)
      {
        if (!connection.Settings.AllowZeroDateTime)
          return typeof(DateTime);
        return typeof(MySqlDateTime);
      }
      return v.SystemType;
    }

Same methods

MySqlDataReader::GetFieldType ( string column ) : Type

Usage Example

        private MySqlSchemaCollection GetTable(string sql)
        {
            MySqlSchemaCollection c      = new MySqlSchemaCollection();
            MySqlCommand          cmd    = new MySqlCommand(sql, connection);
            MySqlDataReader       reader = cmd.ExecuteReader();

            // add columns
            for (int i = 0; i < reader.FieldCount; i++)
            {
                c.AddColumn(reader.GetName(i), reader.GetFieldType(i));
            }

            using (reader)
            {
                while (reader.Read())
                {
                    MySqlSchemaRow row = c.AddRow();
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        row[i] = reader.GetValue(i);
                    }
                }
            }
            return(c);
        }
All Usage Examples Of MySql.Data.MySqlClient.MySqlDataReader::GetFieldType