Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8645735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:37:31+00:00 2026-06-12T12:37:31+00:00

I am using a DataTable in my .Net 3.5 application to store 1 column,

  • 0

I am using a DataTable in my .Net 3.5 application to store 1 column, with some records that contain a filename.

Here is my code on how and where I initialize my DataTable:

public partial class MainForm : Form
{
    DataTable memTable_CurrentTransfers = new DataTable();


private void MainForm_Load(object sender, EventArgs e)
{
    memTable_CurrentTransfers.Columns.Add("fileName", typeof (string));

Here is how I add the filename to my DataTable in another method of my application:

memTable_CurrentTransfers.Rows.Add(fileName);

Every 30 minutes, I launch a thread that executes this code:

public void CheckUploads()
{
   DataView view2 = memTable_CurrentTransfers.DefaultView;

   for (int i = 0; i < view2.Count; i++)
   {
     string tmpString = view2[i][0].ToString();

Everything works great, but after after my application is running for a while, my users are starting to get this error in the CheckUploads() method

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.get_Item(Int32 recordIndex)

I think that my column is disappearing from my DataTable.

Can please anyone tell me why this is happening and how I can stop this from occurring? Is there another way I should be initializing my DataTable so it is available from all methods inside of my application?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:37:33+00:00Added an answer on June 12, 2026 at 12:37 pm

    For a start, a DataTable is not thread-safe, and the code you posted doesn’t include any synchronisation.

    Can you elaborate on “doesn’t include any Synchronization”?

    You say you have multiple threads accessing the DataTable: your CheckUploads method is on a background thread, and, presumably, there is code to add (and possibly remove) rows in your main thread.

    I’d recommend you design the application such that no synchronization is required. For example, pass a clone of the main DataTable to your background thread, so that there is never more than one thread accessing the same instance.

    I think that my column is disappearing from my DataTable.

    I don’t see any evidence of that: the stack trace seems to show that it’s failing to find a row ( System.Data.DataView.get_Item(Int32 recordIndex)) not a column.

    From ebyrob’s comment:

    lock(memTable_CurrentTransfers) { memTable_CurrentTransfers.Rows.Add(filename) } and similar around every other access to memTable_CurrentTransfers.

    You would also need to use the same lock round any access to the DataView. Though it’s easy to get synchronization wrong, so I stand by the recommendation to design your app so that synchronization isn’t needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using firebird .NET provider and when I do something like this: DataTable.Load(FbCommand.ExecuteReader());
EDIT: I am using VS2008, .NET 3.5 I have a DataTable, which is populated
I'm using JS DataTable and the Date Column must be sortable. But it can't
I have a bit of .NET code that retrieves the results from an Oracle
Im using c# .net windows form application. I have created a database which has
I am using a DataGridView control in a VB.Net application where columns are being
I have an asp.net application, and now I am using datasets for data manipulation.
In Ajax, i am using autocompleteExender in my asp.net application, i write the service
Hello I have the code below that for some reason is not working: I
Im working on asp.net website. In some pages I'm saving the datatable into chache

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.