AddNew Row not consistent..

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

only some rows are being added to dataset when i run this method repeatedly ---any idea why it would skip some rows?

double pid= 0
pid=unique(); \\ generate unique numbe

DataRow newrow2= dataSet11.Tables["tbl1"].NewRow()
newrow2["PropertyID"]=pid
newrow2["Account"]="o"
dataSet11.tbl1.Rows.Add(newrow2)
 
Subt:

It's doubtful it's playing favorites. Is this the exact code snippet or is
it wrapped in a try catch block? depending on the constraints, you could be
generating exceptions and if they aren't using notifiers, this may never be
knows.

To be sure, do this.

At the beginning of the code block add int i =
dataSet11.Tables["tbl1"].Rows.Count;

Then the next line Debug.Assert(dataSet11.Tables["tbl1"].Rows.Count == i);
//This should always be true.

Then after the dataSet11.tbl1.Rows.Add(newrow2); Add the same line of code.
It should bark at you if they aren't the same. there could be a whole lot
of stuff going on but if you get through the add row line and you aren't
throwing an exception then the row is added unless you've found some very
very subtle bug. I have done this literally thousands of times and I've
never even heard of a bug with Rows.Add (unless you consider user error a
bug).

Also, just for clarity, why use different table references?
In line 1 you reference the table this way: dataSet11.Tables["tbl1"]

Then in line 4 you reference it dataSet11.tbl1 I'm guessig you have a STD
based on the line 4 unless that's pseudo code, but either way, I'd verify my
tables and the row count. can you post the whole sub? by default, this
looks like a situation of an exception block not sending a notification (the
random addition of rows is what makes me think this) but it could be a few
other things like different table references depending on how the rest of
the code is layed out. Is this the only problem block?
subt said:
only some rows are being added to dataset when i run this method
repeatedly ---any idea why it would skip some rows?:
double pid= 0;
pid=unique(); \\ generate unique number

DataRow newrow2= dataSet11.Tables["tbl1"].NewRow();
newrow2["PropertyID"]=pid;
newrow2["Account"]="o";
dataSet11.tbl1.Rows.Add(newrow2);
 
william, thanks, it appears you are correct

the code was adding new rows, however it was not displaying the new rows correctly in the datagrid when filtering a dataview. what does not make sense is that the DataAdapter also did not send those rows to the database on Update even though the filter id problem depended on a non- primary key column

also, what is the difference in using dataset.Tables["tbl"] vs. dataset.tbl ?
thanks
 
Subt:

The grid should show those values unless you are bound to a filtered
dataview, then any new rows that don't match the filter criteria will just
'disappear' Usually you can use Default Values for the dataColumns to get
around this.

As far as the update...they should be submitted and if they aren't, one of
two things is probably the problem 1) The rowstate isn't being marked as
Added/Modified/deleted 2) The update command isn't processing it correctly.
A lot of times, if you have a paramaterized where clause and there aren't
any matches, you may have an issue. Similarly, if your row state isn't
marked as one of the changed values, you can call update all year and
nothing will happen. Are you sure you aren't getting any exceptions on
Update?

Unless something is wrong, this shouldn't be happening and most things would
notify you of a problem unless their notifications are turned off or a try
catch isn't handling the exception and is masking the problem.

As far as the difference, they are effectively the same, but C# is case
sensitive and if you have a STD, you can create a new table in lowercase
letters that is totally different from one with upper case letters. It
looked like you were mixing the Strongly typed dataset references with a
weakly typed one, eliminating on of the major benefits of STD's, that's the
ohnly reason I mention it.


Cheers,

Bill
subt said:
william, thanks, it appears you are correct.

the code was adding new rows, however it was not displaying the new rows
correctly in the datagrid when filtering a dataview. what does not make
sense is that the DataAdapter also did not send those rows to the database
on Update even though the filter id problem depended on a non- primary key
column.
also, what is the difference in using dataset.Tables["tbl"] vs. dataset.tbl ??
thanks
 
Back
Top