Forum guidelines
Data grid problem in windows application using c#
Posted By swapnil jatkar on 25 Feb 2012

I am working on a windows applications using c#. I have a form(parent form) with data grid that displays a records from database. I have a update button near the data grid. When a user selects a record from grid & clicks update button a new form (child form) opens that consists of a form for updating the selected record. The child form consist of a update button that updates the entry in the same database table which is bind to that datagrid. when a user clicks the update button on the child form, all the data gets updated in the database & the child form gets closed. Now the focus comes on parent form, but the datagrid don't show the changes happened in the database,even though it is bind after update the database.

I have also tried to null the datasource before binding after updation.

Need some urgent help..

Thanks in Advance.

 private void butBilling_update_Click(object sender, EventArgs e)
  if (DGV_outward.SelectedRows.Count > 0)
  String bill_no = DGV_outward.SelectedRows[0].Cells[0].Value.ToString();
  update_bill b = new update_bill(bill_no);        <--------------- Update is name of child form,,on which update form is designed

  OleDbConnection con = new OleDbConnection(ConnectionString);
  cmd = new OleDbCommand("select * from dbo_Outward_Billing order by Outward_bill_ID desc", con);
  dr = cmd.ExecuteReader();
  DataTable dt = new DataTable();
  DGV_outward.DataSource = dt;

  MessageBox.Show("Select a record");
  catch (Exception ex )
  MessageBox.Show("please select a record for update..");

Re: Data grid problem in windows application using c#
Posted By Mayur Dighe on 25 Feb 2012  

                You can do this .........

                First you remove........this.Refresh(); from your code...
                so that your Chlid Form never get closed after updation of data.....

                       and Second thing is..........that
                Close the DataReader after its use, but before the Connection Close.


My Blog : http://ImmortalDotNet.BlogSpot.Com http://ImmortalDotNet.WordPress.Com
Re: Data grid problem in windows application using c#
Posted By swapnil jatkar on 26 Feb 2012  
Thanks mayur for ur support is always welcome,

But that this.refresh is not closing my child window,even i don't want to keep that open after the update has been done. There is a exit button on that child form, from where it gets closed & also i code to close that child window after updation, for that i have done coding on that child form only. What i want is to make is the changes in datagrid on the parent window just after the updates done through child window,dats it. I thought if after coming back from the child window if the parent window gets refresh then it might show the changes & hence i put this.refresh & nothing else. But it's not working. As u said i also tried to close datareader before con.close. But still it doesn't work. Please help me out..if u have any other solution. Its urgent for me......Thanks a lot once again

Re: Data grid problem in windows application using c#
Posted By Mayur Dighe on 26 Feb 2012  
Hey Swapnil.........

                Well, in that case you need to reset the DataSource of Grid from Parent's Window....

                        you can assign Whole DataTable (from Child window) to the Other DataTable (to Parent Window) BEFORE leaving the Child Window........

        After Code of Updating your DATA
                frmParent.dtable_P= dtable_C;
  //dtable_C --> DataTable Object in Child Form
             //dtable_P --> DataTable Object in Parent Form
(must be PUBLIC)
function is used to Refresh the Components present on the CURRENT Windows Form.
        and not to refresh the Grid's DataSource...

.........Happy .....Prgramming.........

My Blog : http://ImmortalDotNet.BlogSpot.Com http://ImmortalDotNet.WordPress.Com
C# Corner Annual Conference 2016


Spire.Doc - Free .NET Word API
Use Spire.Doc to create, read, write, print, and convert word documents to OpenXML, RTF, TXT, XPS, EPUB, EMF, HTML, Image and PDF.