Amir Mirkamali

امیر میرکمالی

Find column index of a column with full column name in sqldatareader (TableName and ColumnName)

public int GetOrdinal(string tableName, string name)
 {
     DataView schema = GetSchemaTable().DefaultView;
     schema.RowFilter = String.Format("BaseTableName='{0}' AND ColumnName='{1}'", tableName, name);
     if (schema.Count > 0)
         return Convert.ToInt32(schema[0]["ColumnOrdinal"]);
     else
         throw new IndexOutOfRangeException();
 }
Comments are closed