Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this:</p> <pre><code> public List&lt;GSP&gt; GetOwnAirline() { List&lt;GSP&gt; lstGSP = new List&lt;GSP&gt;(); using (ccs = new SqlConnection(Adm.COnnectionString)) { string get_ = "SELECT * FROM " + Adm.schema_ + "Adm.GSP WHERE Description = 'Own Airline'"; using (SqlCommand cmd = new SqlCommand(get_, ccs)) { ccs.Open(); SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (rdr.Read()) { GSP objGSP = new GSP(); Fill(objGSP, rdr);//method lstGSP.Add(objGSP); } ccs.Close(); } } return lstGSP; } public static void Fill(object LogicObject, System.Data.SqlClient.SqlDataReader SqlDataReader) { Dictionary&lt;string, PropertyInfo&gt; props = new Dictionary&lt;string, PropertyInfo&gt;(); foreach (PropertyInfo p in LogicObject.GetType().GetProperties()) props.Add(p.Name, p); //foreach (System.Data.DataColumn col in Row.Table.Columns) for (int i = 0; i &lt; SqlDataReader.FieldCount; i++) { string name = SqlDataReader.GetName(i); if (SqlDataReader[name] != DBNull.Value &amp;&amp; props.ContainsKey(name)) { object item = SqlDataReader[name]; PropertyInfo p = props[name]; if (p.PropertyType.IsGenericType &amp;&amp; p.PropertyType.GetGenericTypeDefinition() == typeof(Nullable&lt;&gt;)) { if (p.PropertyType != SqlDataReader.GetFieldType(i)) item = Convert.ChangeType(item, p.PropertyType.GetGenericArguments()[0]); } else { if (p.PropertyType != SqlDataReader.GetFieldType(i)) item = Convert.ChangeType(item, p.PropertyType); } p.SetValue(LogicObject, item, null); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload