6 Replies - 645 Views - Last Post: 04 August 2010 - 02:02 AM Rate Topic: -----

#1 Muqp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 15-June 10

about getting something from a row by name, not by index

Posted 30 July 2010 - 12:21 AM

I know that i can take something from a row by index, but can i do the same by the name?
Is This A Good Question/Topic? 0
  • +

Replies To: about getting something from a row by name, not by index

#2 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: about getting something from a row by name, not by index

Posted 30 July 2010 - 04:18 AM

Are you talking about a UI grid control? Or getting data directly from a database?
Was This Post Helpful? 0
  • +
  • -

#3 Muqp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 15-June 10

Re: about getting something from a row by name, not by index

Posted 30 July 2010 - 04:54 AM

directly from a database.
Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4419
  • View blog
  • Posts: 7,685
  • Joined: 08-June 10

Re: about getting something from a row by name, not by index

Posted 30 July 2010 - 07:15 AM

You're going to have to be far more clear on your goals here. Do you mean how do you query in sql by column? Do you mean how do you get a cell value from an ADO.NET recordset?

Please clarify your question, and maybe show some sample code of getting it "by index" so that we can help you modify it.
Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1637
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: about getting something from a row by name, not by index

Posted 30 July 2010 - 07:38 AM

Moved to C#. C# Programmers isn't for asking help[ questions, it's for discussions on more advanced topics :)
Was This Post Helpful? 0
  • +
  • -

#6 Muqp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 15-June 10

Re: about getting something from a row by name, not by index

Posted 01 August 2010 - 11:57 PM

OK, so... i have a class :
 public class DatabaseValue
	{
		private bool	_isAssigned;
		private object	_storedObject;


		public bool IsNull
		{
			get
			{
				return !_isAssigned || _storedObject == null;
			}
		}
        

		/// <summary>
		/// assign oracle object
		/// </summary>
		/// <param name="o">oracle object to assign</param>
		/// <returns>this</returns>
		public DatabaseValue Assign(object o)
		{
			_storedObject = o;
			_isAssigned = true;
			return this;
		}

		/// <summary>
		/// indicates assign state of db value
		/// </summary>
		public bool Assigned
		{
			get { return _isAssigned; }
		} 

and this class i use to work with a data that comes from a database. here is an example of a method :
  public List<DatabaseValue[]> ExecuteSQLSelect( string sql, params object[] values )
        {
            if (values != null && values.Length > 0)
			{
                sql = string.Format(sql, values);
			}

            var l_oracleCommand = new OracleCommand
                                    {
                                        Connection = _connection,
                                        CommandText = sql,
                                        CommandType = CommandType.Text
                                    };

            OracleDataReader l_oracleDataReader = null;
            var l_result = new List<DatabaseValue[]>();

            try 
            {
                l_oracleDataReader = l_oracleCommand.ExecuteReader();
                while (l_oracleDataReader.Read())
                {
                    var l_row = new DatabaseValue[ l_oracleDataReader.FieldCount ];
                    for (int i = 0; i < l_oracleDataReader.FieldCount; i++)
                    {
                        var l_databaseValue = new DatabaseValue();
                        l_databaseValue.Assign( l_oracleDataReader.IsDBNull(i) ? null : l_oracleDataReader.GetOracleValue(i) );
                        l_row[i] = l_databaseValue;
                        
                    }
                    
                    l_result.Add(l_row);
                    
                }
            }
            catch (OracleException ex)
            {
                _log.Error(sql);
                _log.Error(values);
                _log.Error(ex.Message);
                
            }
            finally
            {
			// Disposing oracle classes
				l_oracleCommand.Dispose();
                SafeCloseReader( l_oracleDataReader );
                _log.Info(sql);
                _log.Info(values);
                _log.Info("Record succesfully selected");
            }

            return l_result;
        }

so, from all of this thing i know that i can get a value from a recieved row by index. so i am wondering, how will looks a class that could get a value by name?

This post has been edited by Muqp: 01 August 2010 - 11:59 PM

Was This Post Helpful? 0
  • +
  • -

#7 Muqp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 15-June 10

Re: about getting something from a row by name, not by index

Posted 04 August 2010 - 02:02 AM

and is there a way to get a value both, by index and a name ?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1