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

GetValue() public method

Gets the value of the specified column in its native format.
public GetValue ( int i ) : object
i int
return object
    public override object GetValue(int i)
    {
      if (!isOpen)
        Throw(new Exception("No current query in data reader"));
      if (i >= FieldCount)
        Throw(new IndexOutOfRangeException());

      IMySqlValue val = GetFieldValue(i, false);
      if (val.IsNull)
        return DBNull.Value;

      // if the column is a date/time, then we return a MySqlDateTime
      // so .ToString() will print '0000-00-00' correctly
      if (val is MySqlDateTime)
      {
        MySqlDateTime dt = (MySqlDateTime)val;
        if (!dt.IsValidDateTime && connection.Settings.ConvertZeroDateTime)
          return DateTime.MinValue;
        else if (connection.Settings.AllowZeroDateTime)
          return val;
        else
          return dt.GetDateTime();
      }

      return val.Value;
    }

Usage Example

Ejemplo n.º 1
0
        public static void PopulateListView(ListView lst, String strQuery)
        {
            ListViewItem lstItem = null;
            int x;

            lst.Items.Clear();

            conn.Open();
            comm.Connection = conn;
            comm.CommandText = strQuery;
            reader = comm.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    lstItem = lst.Items.Add(reader.GetValue(0).ToString());
                    for (x = 1; x < reader.FieldCount; x++)
                    {
                        lstItem.SubItems.Add(reader.GetValue(x).ToString());
                    }
                }
            }
            conn.Close();
        }
All Usage Examples Of MySql.Data.MySqlClient.MySqlDataReader::GetValue