none
linq to datatable? RRS feed

  • Question

  •  

    Hi Experts,

    I have a datatable with N number of columns and N number of records i dont know how many column is there it'll dynamically create,

     now i want to write a simple query like this

    var query = from mytable in dt.AsEnumerable() where mytable.Field<string>("name").Contains("johny") select mytable; DataTable dttemp = query.CopyToDataTable();
    When the control come above line then it raise an error as{System.Reflection.TargetParameterCountException: Parameter count mismatch.
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
       at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
       at LinqToXML.ObjectShredder`1.ShredObject(DataTable table, T instance) in
    If its working fine if specify the column names in the select clause but in my situation i dont know the column names and datatype,

    I tried with ToDataTable by this link http://weblogs.asp.net/stevesloka/archive/2008/01/28/linq-to-datatable.aspx then it raise   A column named 'Item' already belongs to this DataTable

      Experts please tell me how to solve this problem?
    Jeyaseelan
    Saturday, February 7, 2009 9:27 AM

All replies