Problem adding and saving changes to a dataRow in DataTable
Expand Post »
Hi guys,
Im pretty new to C# and I have a problem hoping that most of you could solve cause you are quite an experienced developers
Here's my problem: I have a simple Windows Application Form with a dataGridView and a button. I want when the button is clicked to fill a simple dataTable and bind it to the dataGridView. The problem is that it always add the same row I mean it adds nine identical rows. But when I put a breakpoint at the end of the outer foreach() everything works great and i have different rows with different values that originlly comes from generateRandomValue(). I tried with row.AcceptChanges() because I think that it's caching row data but no luck again
Re: Problem adding and saving changes to a dataRow in DataTable
Maybe posting the rest of the code (or entire project) will help. The adapter.table is a bit of a mystery.
The acceptchanges is not really needed until later after the rows have all been added. I think the use of the adapter object in the for loop may be at the root of the problem, but until it is more obvious as to what that object is... it is just an assumption.
Maybe posting the rest of the code (or entire project) will help. The adapter.table is a bit of a mystery.
The acceptchanges is not really needed until later after the rows have all been added. I think the use of the adapter object in the for loop may be at the root of the problem, but until it is more obvious as to what that object is... it is just an assumption.
No, it's not neccesary you can try with some random data. You'll always get identical rows. adapter.table is fine, I use it in some other methods and everything works great. As I told you when you put a breakpoion at the end of the outer foreach and continue with F5, it's ok. Maybe the the changes of the row doesn't commit in runtime. I don't know, really
Re: Problem adding and saving changes to a dataRow in DataTable
Paste the code for your generateRandomValue(); method. The problem is likely that when you have a break point that one second passes on your computers clock that changes the seed value for generateRandomValue(). You probably should use another GetRandomValue() method:
System.Security.Cryptography.RNGCryptoServiceProvider Gen = newSystem.Security.Cryptography.RNGCryptoServiceProvider();
Gen.GetBytes(randomNumber);
int rand = Convert.ToInt32(randomNumber[0]);
return rand % Maxvalue + 1;
}
I suspect you are using the "Random" class. This is a quote from the help file:
Quote ...
However, because the clock has finite resolution, creating different Random objects in close succession creates random number generators that produce identical sequences of random numbers. This problem can be avoided by creating a single Random object rather than multiple ones.
This would explain why debugger breaks would change the values since the clock would change in time between calls to generator.
Paste the code for your generateRandomValue(); method. The problem is likely that when you have a break point that one second passes on your computers clock that changes the seed value for generateRandomValue(). You probably should use another GetRandomValue() method:
I just use it cause I have to choose a random value from the current column. To be more clear I have a table with 3000 genes and based on that table I have to generate artificial profiles of new genes.
and i call it when i fill the data table like this :
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.