473,405 Members | 2,176 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,405 software developers and data experts.

updating datagrid after returning

After clicking btnDeleteSize_Click in frmSize, I move to frmSizeDelete, allow
deleting a Size using a datagrid, and then return to frmSize and want to
update the datagrid in frmSize to reflect the deletion. I can't figure out
how to get the datagrid in frmSize updated, although the datagrid in
frmSizeDelete shows the deletion properly.

In frmSizeDelete the size is properly deleted when the user clicks the row
in the datagrid and presses the delete key:

private void frmSizeDelete_Load(object sender, System.EventArgs e)
{
strCommandText = "SELECT SizeID, SizeName FROM tblSize WHERE SizeID = '" +
strCurrentSize + "'";
this.oleDbSelectCommand1.CommandText = strCommandText;
oleDbDataAdapter1.Fill(dsSizeDelete1);
}

private void frmSizeDelete_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
oleDbDataAdapter1.Update(dsSizeDelete1);
}

However, when I return to frmSize I can't figure out how to show the updated
datagrid.
The following code has no errors, but doesn't work:

private void btnDeleteSize_Click(object sender, System.EventArgs e)
{
// dgSize.ReadOnly = false; (dgSize is readonly, does this matter in showing
the update?)
DialogResult button =
MessageBox.Show("Are you sure you want to delete this size? This size will
be deleted from ALL product parts!!!", "Delete Size",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
if (button ==DialogResult.Yes)
{
Form newSizeDeleteForm = new frmSizeDelete(txtSizeID.Text);
newSizeDeleteForm.Show();
dsSize1.Clear();
oleDbDataAdapterSize.Fill(dsSize1);
oleDbDataAdapterSize.Update(dsSize1);
dgSize.Update();
dgSize.Show();

I added these last 5 statements in the hopes of making the datagrid in
frmSize show the change, and I don't know if any of them are needed, but they
do not show the change as expected. What should I do?

Thanks,
Pam
Nov 16 '05 #1
9 1626
Hi Pam,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to delete a row of the
DataSet, update it to data source and update the data grid. If there is any
misunderstanding, please feel free to let me know.

Based on the code you have provided, I didn't see any delete code to delete
that row in the DataSet table. When deleting and refreshing, we have 2
choices.

The first is to delete in the current DataSet in frmSize and use an
DataAdapter to update it to the data source. Since the datagrid in bound to
DataSet, when data in it changes, it will automatically show the changes.
For example, I need to delete a row dr.

dr.Delete();
oleDbDataAdapterSize.Update(dsSize1);

The second is to delete data directly in the database and then re-fill the
DataSet with updated data.

dsSize1.Clear();
oleDbDataAdapterSize.Fill(dsSize1);

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #2
Thank you, but this didn't help since it is already what I am doing. It
still doesn't work.

To answer your question, I used the datagrid built in features to delete the
row - user highlights the row and presses delete. That part works fine. It
also shows the deletion fine in the dgSizeDelete in the frmSizeDelete. It is
when I return to the calling form, frmSizes and want the Datagrid, dgSize, in
the calling form to update that I have a problem.

As you can see from my initial post,
dsSize1.Clear();
oleDbDataAdapterSize.Fill(dsSize1);
is exactly what I did. And dgSize did not show the change in frmSize when I
return to it. This is why I added the 3 lines of code after it to try to get
the datagrid to show the change.

I just tried it again, commenting out the 3 additional lines of code. It
still doesn't work.

What I think you don't understand is that your example of code is not the
datagrid that I am having a problem with, it is the datagrid I return to in
the calling form that is a problem.

Pam

"Kevin Yu [MSFT]" wrote:
Hi Pam,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to delete a row of the
DataSet, update it to data source and update the data grid. If there is any
misunderstanding, please feel free to let me know.

Based on the code you have provided, I didn't see any delete code to delete
that row in the DataSet table. When deleting and refreshing, we have 2
choices.

The first is to delete in the current DataSet in frmSize and use an
DataAdapter to update it to the data source. Since the datagrid in bound to
DataSet, when data in it changes, it will automatically show the changes.
For example, I need to delete a row dr.

dr.Delete();
oleDbDataAdapterSize.Update(dsSize1);

The second is to delete data directly in the database and then re-fill the
DataSet with updated data.

dsSize1.Clear();
oleDbDataAdapterSize.Fill(dsSize1);

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #3
Hi Pam,

The dataGrid which show dsSize1 doesn't get updated, because when you call
newSizeDeleteForm.Show();, you assume that the code behind this line will
be suspended. They will wait for the newSizeDeleteForm to close, update the
database and continue executing with updated values.

Actually, the code didn't suspend. It goes down before newSizeDeleteForm
got a chance to delete data on the database, which mean they we run in two
threads. I suggest you to use newSizeDeleteForm.ShowDialog() instead of
newSizeDeleteForm.Show(). That might help you out of the problem.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #4
Sorry, it still doesn't work. What you said makes sense, so I don't
understand why it is not working. Any other suggestions?

Or is there a better way to write my code? What I am trying to do is to
drill down, so I go from frmPart to frmSize and then I either Add, Edit or
Delete a Size. Then I come back up to work on the next part.

Or perhaps you want me to zip my code to you?

I really need to figure out a way to get this project finished so I can get
paid and move on to other things. I'm losing money with all the time I've
spent trying to find ways around things I can't do. Any suggestions would be
appreciated.

Thanks,
Pam
Nov 16 '05 #5
Actually, it almost works. I go from frmSize to frmSizeDelete, delete the
Size and return to frmSize and it still doesn't show that it works. But then
I go back to frmSizeDelete (which now shows nulls because the Size actually
is deleted), don't do anything but close the frmSizeDelete a second time, and
then when I go back to frmSize the original deletion shows up. Why doesn't
it work the first time? How can I make it work the first time?

Thanks,
Pam

"Pam Ammond" wrote:
Sorry, it still doesn't work. What you said makes sense, so I don't
understand why it is not working. Any other suggestions?

Or is there a better way to write my code? What I am trying to do is to
drill down, so I go from frmPart to frmSize and then I either Add, Edit or
Delete a Size. Then I come back up to work on the next part.

Or perhaps you want me to zip my code to you?

I really need to figure out a way to get this project finished so I can get
paid and move on to other things. I'm losing money with all the time I've
spent trying to find ways around things I can't do. Any suggestions would be
appreciated.

Thanks,
Pam

Nov 16 '05 #6
Hi Pam,

This is strange. Could you please zip the code and send it to my email with
the repro steps? Removing 'online' from the no spam alias is my real email.
It will be faster for us to find out the problem with the repro code.
Thanks for your cooperation.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #7
Hi Pam,

When I changed newSizeDeleteForm.Show(); to
newSizeDeleteForm.ShowDialog();, everything works fine. The DataGrid gets
updated when Done is clicked. HTH.

I have send the changed code to your mailbox. Thanks.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #8
Kevin,

I apologize, I see that in my code I incorrectly put the ShowDialog(); on
the wrong button. Thank you for your correction.

I still am wondering... it deletes fine in YOUR code that you sent me. But
in my code it appears to show as fully deleted once I click back into the
datagrid, while yours doesn't need that. I'm not complaining that much since
at least it now works. I was just wondering if there is anything else that
you remember as changing in your code that isn't in mine?

Is there any way to search two copies of code in two separate Solutions and
find only the differences between the two copies?

Is there another way to ask VS.NET to check my code more completely other
than pressing the Start-Debug button? My code seems flaky and I'm wondering
if it is damaged in some way that I'm not aware of.

But regardless of my flaky result, yours definitely works. THANKS!!!!

Pam

Nov 16 '05 #9
Hi Pam,

As far as I can remember, I only changed some code in that button event
handler. Nothing else.

There are some tools for us to compare codes such are WinDiff.exe. It is
shipped with platform SDK. However, there are some 3rd-party front-end for
us to use it easier. You can find one from the following link:

http://www.codeproject.com/tools/runwindiff.asp

There doesn't seem to be any way in VS.NET to check our code more
completely. Since we can only get compilation error at compile time and
runtime error at runtime.

Thanks!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #10

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

Similar topics

0
by: cwbp17 | last post by:
Have two tables that have a FK relationship on ID column. Have one datagrid that displays all of the columns of both tables. What's the best approach on updating a row from the datagrid back to...
1
by: Bryan Masephol | last post by:
Hi All I have a OleDbConnection as the "connection" below. I'm retriving a dataset from an access 2002 db and displaying it in a DataGrid. I'm making the connection to my access db file with...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
0
by: cwbp17 | last post by:
I'm having trouble updating individual datagrid cells. Have two tables car_master (columns include Car_ID, YEAR,VEHICLE) and car_detail (columns include Car_ID,PRICE,MILEAGE,and BODY);both tables...
10
by: jaYPee | last post by:
does anyone experienced slowness when updating a dataset using AcceptChanges? when calling this code it takes many seconds to update the database SqlDataAdapter1.Update(DsStudentCourse1)...
0
by: Mike P | last post by:
I'm updating a datagrid which works fine, but after updating the datagrid does not return to 'view' status, remaining in 'edit' status. Has anybody else had this problem? Thanks, Mike
2
by: Greg | last post by:
I'm using the Framework 1.1, so I don't have access to the new DataGridView object. What I'm wondering is, is there a really simple way to bind a plain datagrid to a database in such a way that...
2
by: marcmc | last post by:
Hey, I have never used a datagrid/dataset/adaptor/table method for updating data, I have always used direct updates to the database so ADO is quite new to me. I have a datagrid and I change a...
0
by: Chet | last post by:
I have a Datagrid that is bound to a Datatable at runtime. I allow the user to select a number of rows using the mouse and then click a button that says "check selected rows", which then cycles...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.