using System;
using System.Data;

namespace edu.jhu.Cas.Util
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	public class DataSetUtils
	{
		//fix this someday (indexof)
		public static int ColumnIndex(DataSet ds, string columnName){
			for(int x=0;x<ds.Tables[0].Columns.Count;x++){
				DataColumn dc = ds.Tables[0].Columns[x];
				//if(dc.ColumnName.ToUpper().CompareTo(columnName.ToUpper()) == 0)
				if(dc.ColumnName.IndexOf(columnName) != -1)
					return x;
			}
			return -1;
		}
		
		public static object[] ColumnValues(DataSet ds, string columnName){
			int i = ColumnIndex(ds, columnName);
			if(i == -1)throw new Exception("Column "+columnName+" does not exist.");
			object[] rst = new object[ds.Tables[0].Rows.Count];
			for(int x=0; x<ds.Tables[0].Rows.Count;x++)
				rst[x] = ds.Tables[0].Rows[x][i];
			return rst;
		}
	}
}
