locked
System.ThrowHelper.ThrowKeyNotFoundException() "The given key was not present in the dictionary" RRS feed

  • Question

  • User2464751 posted

    Hi everyone,

    i got this exception as

     at System.ThrowHelper.ThrowKeyNotFoundException()
    at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
    at System.Data.DataView.CopyTo(DataRowView[] array, Int32 index)
    at System.Data.DataView.GetEnumerator()
    at System.Data.DataView.ToTable(String tableName, Boolean distinct, String[] columnNames)
    at System.Data.DataView.ToTable()

    System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
    at System.ThrowHelper.ThrowKeyNotFoundException()
    at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
    at System.Data.DataView.CopyTo(DataRowView[] array, Int32 index)
    at System.Data.DataView.GetEnumerator()
    at System.Data.DataView.ToTable(String tableName, Boolean distinct, String[] columnNames)
    at System.Data.DataView.ToTable()
    
    
    when i used to get value from datatable like this
    string strname=dtSample.DefaultView.ToTable().Rows[0]["FirstName"].ToString();
    this look seems to be right code line but why i am getting exception in this line , 
    please help
    
    
    Regards,
    Elango
    Friday, July 1, 2011 12:57 AM

Answers

  • User3866881 posted

    Hi everyone,

    i got this exception as

     at System.ThrowHelper.ThrowKeyNotFoundException()
    at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
    at System.Data.DataView.CopyTo(DataRowView[] array, Int32 index)
    at System.Data.DataView.GetEnumerator()
    at System.Data.DataView.ToTable(String tableName, Boolean distinct, String[] columnNames)
    at System.Data.DataView.ToTable()

    System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
    at System.ThrowHelper.ThrowKeyNotFoundException()
    at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
    at System.Data.DataView.CopyTo(DataRowView[] array, Int32 index)
    at System.Data.DataView.GetEnumerator()
    at System.Data.DataView.ToTable(String tableName, Boolean distinct, String[] columnNames)
    at System.Data.DataView.ToTable()
    
    
    when i used to get value from datatable like this
    string strname=dtSample.DefaultView.ToTable().Rows[0]["FirstName"].ToString();
    this look seems to be right code line but why i am getting exception in this line , 
    please help
    
    
    Regards,
    Elango

    Hello:)

    According to this problem, I think you should check the field "FirstName" is really in the DataTable or not. If possible, please show us your codes, Please.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, July 3, 2011 9:25 PM

All replies

  • User181256233 posted

    Looks like there is no key named FirstName in the table?

    Friday, July 1, 2011 1:01 AM
  • User3866881 posted

    Hi everyone,

    i got this exception as

     at System.ThrowHelper.ThrowKeyNotFoundException()
    at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
    at System.Data.DataView.CopyTo(DataRowView[] array, Int32 index)
    at System.Data.DataView.GetEnumerator()
    at System.Data.DataView.ToTable(String tableName, Boolean distinct, String[] columnNames)
    at System.Data.DataView.ToTable()

    System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
    at System.ThrowHelper.ThrowKeyNotFoundException()
    at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
    at System.Data.DataView.CopyTo(DataRowView[] array, Int32 index)
    at System.Data.DataView.GetEnumerator()
    at System.Data.DataView.ToTable(String tableName, Boolean distinct, String[] columnNames)
    at System.Data.DataView.ToTable()
    
    
    when i used to get value from datatable like this
    string strname=dtSample.DefaultView.ToTable().Rows[0]["FirstName"].ToString();
    this look seems to be right code line but why i am getting exception in this line , 
    please help
    
    
    Regards,
    Elango

    Hello:)

    According to this problem, I think you should check the field "FirstName" is really in the DataTable or not. If possible, please show us your codes, Please.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, July 3, 2011 9:25 PM