473,320 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Deleting a Record From a Data Table

I have an app that populates several data tables on load. Each of
these are bound to a datagrid. Above each datagrid I have several
text boxes that display the data for the active row. There are
buttons to allow the user to add, update, and delete a row in the
grid. I have an event on cell changed associated with the grid that
updates the text boxes so they are always current.

When the delete button is used I'm getting an error that ""Deleted row
information cannot be accessed through the row."

Here's what I want to happen:

1. User selects a row
2. The contents of the row appear in the appropiate text boxes
3. User presses delete button
4. Row is marked for deletion when dataset changes are written back
and not shown in the grid
5. text boxes are updated to show the next row.

Here's my method to update the text boxes:

UpdateTextBoxes()
{
int curSelection = dgMembForm.CurrentRowIndex;
DataRow r = dTable.Rows[curSelection];

txtMemberName.Text = r["Account"].ToString();
rtbMemberFormula.Text = r["Member Formula"].ToString();
)

The event on cell changed just calls this method

Heres the code for the delete button:

private void btnDelete_Click(object sender, EventArgs e)
{
DataRow selectedRow = this.SelectedRow(dTable,
dgMembForm);
int sRow = dgMembForm.CurrentCell.RowNumber;
dTable.Rows[sRow].Delete();
dgMembForm.CurrentRowIndex = 0;
UpdateTextBoxes();
}
I added the piece to set index to 0 to solve a similar problem when
the last row was deleted.

Mar 16 '07 #1
3 2216
VJ
So what happens if they select the first row and delete?.. I don't think
what your doing will work all situations.. You may want to select next
available row or something. Also after delete call AcceptChanges()

VJ

"Ctal" <wi********@yahoo.comwrote in message
news:11*********************@p15g2000hsd.googlegro ups.com...
>I have an app that populates several data tables on load. Each of
these are bound to a datagrid. Above each datagrid I have several
text boxes that display the data for the active row. There are
buttons to allow the user to add, update, and delete a row in the
grid. I have an event on cell changed associated with the grid that
updates the text boxes so they are always current.

When the delete button is used I'm getting an error that ""Deleted row
information cannot be accessed through the row."

Here's what I want to happen:

1. User selects a row
2. The contents of the row appear in the appropiate text boxes
3. User presses delete button
4. Row is marked for deletion when dataset changes are written back
and not shown in the grid
5. text boxes are updated to show the next row.

Here's my method to update the text boxes:

UpdateTextBoxes()
{
int curSelection = dgMembForm.CurrentRowIndex;
DataRow r = dTable.Rows[curSelection];

txtMemberName.Text = r["Account"].ToString();
rtbMemberFormula.Text = r["Member Formula"].ToString();
)

The event on cell changed just calls this method

Heres the code for the delete button:

private void btnDelete_Click(object sender, EventArgs e)
{
DataRow selectedRow = this.SelectedRow(dTable,
dgMembForm);
int sRow = dgMembForm.CurrentCell.RowNumber;
dTable.Rows[sRow].Delete();
dgMembForm.CurrentRowIndex = 0;
UpdateTextBoxes();
}
I added the piece to set index to 0 to solve a similar problem when
the last row was deleted.

Mar 16 '07 #2
"Ctal" <witp_tu...@yahoo.comwrote in message
>
news:11*********************@p15g2000hsd.googlegro ups.com...
I have an app that populates several data tables on load. Each of
these are bound to a datagrid. Above each datagrid I have several
text boxes that display the data for the active row. There are
buttons to allow the user to add, update, and delete a row in the
grid. I have an event on cell changed associated with the grid that
updates the text boxes so they are always current.
When the delete button is used I'm getting an error that ""Deleted row
information cannot be accessed through the row."
Here's what I want to happen:
1. User selects a row
2. The contents of the row appear in the appropiate text boxes
3. User presses delete button
4. Row is marked for deletion when dataset changes are written back
and not shown in the grid
5. text boxes are updated to show the next row.
Here's my method to update the text boxes:
UpdateTextBoxes()
{
int curSelection = dgMembForm.CurrentRowIndex;
DataRow r = dTable.Rows[curSelection];
txtMemberName.Text = r["Account"].ToString();
rtbMemberFormula.Text = r["Member Formula"].ToString();
)
The event on cell changed just calls this method
Heres the code for the delete button:
private void btnDelete_Click(object sender, EventArgs e)
{
DataRow selectedRow = this.SelectedRow(dTable,
dgMembForm);
int sRow = dgMembForm.CurrentCell.RowNumber;
dTable.Rows[sRow].Delete();
dgMembForm.CurrentRowIndex = 0;
UpdateTextBoxes();
}
I added the piece to set index to 0 to solve a similar problem when
the last row was deleted.- Hide quoted text -

- Show quoted text -
On Mar 16, 3:00 pm, "VJ" <nonewsaddr...@yahoo.comwrote:
So what happens if they select the first row and delete?.. I don't think
what your doing will work all situations.. You may want to select next
available row or something. Also after delete call AcceptChanges()

VJ
I should have added that the problem occurs only when they delete the
first record. When UpdateTextBoxes() runs after that, it gives the
message about Deleted row access.

I save changes back to the database through another method, hoping to
give they user the opportunity to make multiple changes before I
update the data adapter.

Assuming the first row in the data table is marked for delete how do I
get the next row?

Mar 16 '07 #3
VJ
the first row is 0.. So you will have to select next row which is 1 before
AcceptChanges() and 0 after AcceptChanges().

VJ

"Ctal" <wi********@yahoo.comwrote in message
news:11*********************@n76g2000hsh.googlegro ups.com...
>"Ctal" <witp_tu...@yahoo.comwrote in message

news:11*********************@p15g2000hsd.googlegr oups.com...
>I have an app that populates several data tables on load. Each of
these are bound to a datagrid. Above each datagrid I have several
text boxes that display the data for the active row. There are
buttons to allow the user to add, update, and delete a row in the
grid. I have an event on cell changed associated with the grid that
updates the text boxes so they are always current.
When the delete button is used I'm getting an error that ""Deleted row
information cannot be accessed through the row."
Here's what I want to happen:
1. User selects a row
2. The contents of the row appear in the appropiate text boxes
3. User presses delete button
4. Row is marked for deletion when dataset changes are written back
and not shown in the grid
5. text boxes are updated to show the next row.
Here's my method to update the text boxes:
UpdateTextBoxes()
{
int curSelection = dgMembForm.CurrentRowIndex;
DataRow r = dTable.Rows[curSelection];
txtMemberName.Text = r["Account"].ToString();
rtbMemberFormula.Text = r["Member Formula"].ToString();
)
The event on cell changed just calls this method
Heres the code for the delete button:
private void btnDelete_Click(object sender, EventArgs e)
{
DataRow selectedRow = this.SelectedRow(dTable,
dgMembForm);
int sRow = dgMembForm.CurrentCell.RowNumber;
dTable.Rows[sRow].Delete();
dgMembForm.CurrentRowIndex = 0;
UpdateTextBoxes();
}
I added the piece to set index to 0 to solve a similar problem when
the last row was deleted.- Hide quoted text -

- Show quoted text -

On Mar 16, 3:00 pm, "VJ" <nonewsaddr...@yahoo.comwrote:
>So what happens if they select the first row and delete?.. I don't think
what your doing will work all situations.. You may want to select next
available row or something. Also after delete call AcceptChanges()

VJ

I should have added that the problem occurs only when they delete the
first record. When UpdateTextBoxes() runs after that, it gives the
message about Deleted row access.

I save changes back to the database through another method, hoping to
give they user the opportunity to make multiple changes before I
update the data adapter.

Assuming the first row in the data table is marked for delete how do I
get the next row?

Mar 16 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mark | last post by:
This question refers to a main form with a continuous form subform. After an error occurs after entering several records in the subform, how can I delete all the data in the main form and all the...
3
by: Nathan Bloom | last post by:
Hi, I have a data entry form (access 2000) that also allows the user to add, update, and delete records from the form. The Delete action is carried out in an event procedure and has the...
1
by: KC | last post by:
Hello, I am using Access 2002. WinXP, Template from MS called Orders Mgmt DB. I have tweaked this DB to work for our small co. It has worked pretty well up until I made the mistake of deleting...
46
by: DP | last post by:
hi, i've got a form, with a subform in it. i've got a delete button in the subform. the code i;ve got is; Private Sub cmdDeleteRecord_Click() msg = "Are you sure you want to delete this...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
7
by: Susan Mackay | last post by:
I have a data table that is connected to a database table with a data adapter in the 'standard' manner. However I want to be able to remove selected rows from the data table (i.e. no longer...
24
by: Frank Swarbrick | last post by:
We have a batch process that inserts large numbers (100,000 - 1,000,000) of records into a database each day. (DL/I database.) We're considering converting it to a DB2 table. Currently we have...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
2
by: robertns5411 | last post by:
I have two questions: 1) Say I have a form bound to a table. Assume the user is entering data into a new record at the bottom of the form. Now, suppose the user clicks a button on the form...
4
by: sphinney | last post by:
I'm not exactly sure how to start this post. My question is pretty simple, but it will take a little bit of context before I can state it. (And thanks in advance for taking the time to read this!) ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.