LINQ - Stored Procedure + Linq + DataTable - Asked By Er Suresh Ganesan on 28-May-09 07:39 AM

I have a StoredProcedure that Return a Result Set. How could i use in LINQ Concept. In lot of wesite they gave for Query. Not for a SP. If any one having Idea?

re - Rao B replied to Er Suresh Ganesan on 28-May-09 08:07 AM

Thank - Er Suresh Ganesan replied to Rao B on 28-May-09 08:23 AM

Thank U Very Muc for your Immediate Reply. I got it.


oDC - is DatacontexName.

DataTable dt = new DataTable();

var result = oDC.Proc_Get_CompanyCode_And_Name();

dt = ObtainDataTableFromIEnumerable(result);

return dt;

 

public DataTable ObtainDataTableFromIEnumerable(System.Collections.IEnumerable ien)

{

DataTable dt = new DataTable();

foreach (object obj in ien)

{

Type t = obj.GetType();

PropertyInfo[] pis = t.GetProperties();

if (dt.Columns.Count == 0)

{

foreach (PropertyInfo pi in pis)

{

dt.Columns.Add(pi.Name, pi.PropertyType);

}

}

DataRow dr = dt.NewRow();

foreach (PropertyInfo pi in pis)

{

object value = pi.GetValue(obj, null);

dr[pi.Name] = value;

}

dt.Rows.Add(dr);

}

return dt;

}

welcome - Rao B replied to Er Suresh Ganesan on 28-May-09 08:34 AM

end of post
Thank - Asked By Er Suresh Ganesan on 28-May-09 08:51 AM
Thank you very Much for ur Reply Mr.Pintu. I got it.