Visual C# Developer Center > Visual C# Forums > Visual C# General > Check whether column name exist in IQueriable<DataRow>
Ask a questionAsk a question
 

AnswerCheck whether column name exist in IQueriable<DataRow>

  • Tuesday, November 03, 2009 9:16 AMrodniko Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    i check whether column name exist in IQueriable<DataRow> by copy the data to a DataTable and then check whehter the column exist:

    myQueriableData.CopyToDataTable().Columns.Contains("MyColumn")

    is CopyToDataTable() the only way to check whether the colum name exist ? can i check for the column name in Linq on myQueriableData?
    i think that transforming the data into a datatable each time i check, will slow down the application....

Answers

  • Tuesday, November 03, 2009 9:46 AMLingzhi SunMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi rodniko,

     

    We can directly get the DataTable of a certain DataRow by calling DataRow.Table property. 

    ==========================================================
    myQueriableData.First().Table.Columns.Contains(“MyColumn”);
    ==========================================================

     

    If you have any questions, please feel free to let me know.

     

    Have a nice day!

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked As Answer byrodniko Sunday, November 08, 2009 11:36 AM
    •  

All Replies

  • Tuesday, November 03, 2009 9:44 AMViral Jain Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Would following work?

    bool isColumnThere = (from DataRow dRow
                                          in YourQueriableList
                                          where dRow.Table.Columns.Contains("YourColumnName")
                                         select 0).Count() > 0 ? true : false;

    Thanks,
    Viral.
                                        
  • Tuesday, November 03, 2009 9:46 AMLingzhi SunMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi rodniko,

     

    We can directly get the DataTable of a certain DataRow by calling DataRow.Table property. 

    ==========================================================
    myQueriableData.First().Table.Columns.Contains(“MyColumn”);
    ==========================================================

     

    If you have any questions, please feel free to let me know.

     

    Have a nice day!

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked As Answer byrodniko Sunday, November 08, 2009 11:36 AM
    •  
  • Thursday, November 05, 2009 12:50 AMLingzhi SunMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi rodniko,

     

    Does the workaround helpful to you? 

     

    If you need any further assistance, please feel free to let me know.

     

    Have a nice day!

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Sunday, November 08, 2009 11:37 AMrodniko Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Works great , thanks!