I have a bound DataGridView control where I wish to add a new row. The simple solution turns out to be add a new row to the underlying datatable object and the changes will automatically reflect in the grid. However, I seem to have caught something bad.
My query is something like this:
select * from [order] where orderid=x
this returns zero records in the dataset.
I bind the grid to the dataset as below:
grid.DataSource = ds; grid.DataMember = "order"
now, I want to add a new row in the grid.. as follows:
ds.Rows.Add(ds.Tables["order"].NewRow());
after this, I check the rows in the grid: grid.Rows.Count.. it shows 0
Pl note that when my query returns >=1 rows then the above works just fine.
Any idea if i'm missing something here?
Cheers! D2
dapi Tuesday, April 10, 2007 2:44 PM
Allright guys, I seem to have caught the issue. Here's my scenario (for future users):
1. I have a base form that does all the databinding stuff with all controls put on derived forms 2.This base form uses a custom DAL for data operations
I was getting the issue when I was debugging in the VS2005 i.e. my grid was not getting the blank row when i was adding a row in the underlying datatable object (only when datatable was having 0 rows).
After trying various methods and debugging for 2 days.. one fine morning I removed all the breakpoints and started the program without any changes in the logic. It just started running. Today I'm not very confident on this piece of code but it seems to be running for now.
Could anyone explain what are the things that IDE does when debugging.
Cheers! D2
dapi Monday, April 16, 2007 4:50 AM
After creating a new row,
Code Snippet
ds.Tables["order"].NewRow();
Have you tried to input all therequired record data(forfields that are declared with NOT NULL or for primary key in case it's not generated automatically)for that newly created row?
skim milk Tuesday, April 10, 2007 3:31 PM
Your code seems no problem,could you please paste more code,or you canuse dataview instead.
Gavin Jin - MSFT Wednesday, April 11, 2007 1:37 AM
Allright guys, I seem to have caught the issue. Here's my scenario (for future users):
1. I have a base form that does all the databinding stuff with all controls put on derived forms 2.This base form uses a custom DAL for data operations
I was getting the issue when I was debugging in the VS2005 i.e. my grid was not getting the blank row when i was adding a row in the underlying datatable object (only when datatable was having 0 rows).
After trying various methods and debugging for 2 days.. one fine morning I removed all the breakpoints and started the program without any changes in the logic. It just started running. Today I'm not very confident on this piece of code but it seems to be running for now.
Could anyone explain what are the things that IDE does when debugging.