473,563 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Curr entRowIndex;
DataRow r = dTable.Rows[curSelection];

txtMemberName.T ext = r["Account"].ToString();
rtbMemberFormul a.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.SelectedRo w(dTable,
dgMembForm);
int sRow = dgMembForm.Curr entCell.RowNumb er;
dTable.Rows[sRow].Delete();
dgMembForm.Curr entRowIndex = 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 2228
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********@yah oo.comwrote in message
news:11******** *************@p 15g2000hsd.goog legroups.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.Curr entRowIndex;
DataRow r = dTable.Rows[curSelection];

txtMemberName.T ext = r["Account"].ToString();
rtbMemberFormul a.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.SelectedRo w(dTable,
dgMembForm);
int sRow = dgMembForm.Curr entCell.RowNumb er;
dTable.Rows[sRow].Delete();
dgMembForm.Curr entRowIndex = 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...@yah oo.comwrote in message
>
news:11******** *************@p 15g2000hsd.goog legroups.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.Curr entRowIndex;
DataRow r = dTable.Rows[curSelection];
txtMemberName.T ext = r["Account"].ToString();
rtbMemberFormul a.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.SelectedRo w(dTable,
dgMembForm);
int sRow = dgMembForm.Curr entCell.RowNumb er;
dTable.Rows[sRow].Delete();
dgMembForm.Curr entRowIndex = 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********@yah oo.comwrote in message
news:11******** *************@n 76g2000hsh.goog legroups.com...
>"Ctal" <witp_tu...@yah oo.comwrote in message

news:11******* **************@ p15g2000hsd.goo glegroups.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.Curr entRowIndex;
DataRow r = dTable.Rows[curSelection];
txtMemberName.T ext = r["Account"].ToString();
rtbMemberFormul a.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.SelectedRo w(dTable,
dgMembForm);
int sRow = dgMembForm.Curr entCell.RowNumb er;
dTable.Rows[sRow].Delete();
dgMembForm.Curr entRowIndex = 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
6097
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 records in the subform? I have tried undoing both the main form and the subform and I have tried deleting the record in the main form. Thanks! ...
3
2747
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 following code: Private Sub Command28_Click() On Error GoTo Err_Command28_Click
1
2383
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 about 80 records from the Orders table. 80 out of a 1000 records. Now our data entry form shows our customer addresses, but not customer order...
46
4386
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 film rental record?" Style = vbYesNo + vbQuestion + vbDefaultButton2
5
3981
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone | ------------------------------------------------------- | mr x | 8th lane | 124364 | | mr x | 6th lane | 435783 | | mrs x | 6th lane |...
7
6591
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 include them in the set that is displayed to the user) but I don't want to delete the corresponding row from the database. I've tried using the...
24
21551
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 logic in place that, prior to inserting any data, reads the first input record and checks to see if it already exists in the table. If the record...
11
3654
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) and the 'employee name'. There is another table which assigns an ID to the Shifts, i.e. 1,2 and 3 for morn, eve & night shifts respectively. From...
2
1688
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 while he's still entering data and hasn't yet saved the record that he is modifying. How can the button's click event procedure test to know that...
4
2383
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!) Context: What I'm essentially trying to do is create a poor man's document imaging system in Access 2007. I have a database that contains forms and...
0
7659
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7580
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7634
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6244
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5208
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3618
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2079
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.