Employers - Post Free Jobs
Forum guidelines
AuthorQuestion
Data grid problem in windows application using c#
Posted on: 25 Feb 2012
hi,

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)
  {
 
  try
  {
  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
  b.Show();
  this.Refresh();

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

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




AuthorReply
Re: Data grid problem in windows application using c#
Posted on: 25 Feb 2012  
hey...........Swapnil......

                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.




..........Happy......Programming.......

Mayur B. Dighe:
If you help Someone without any Expectations, Somebody else will Definitely help you.

My Blog : ImmortalDotNET.BlogSpot.com
Re: Data grid problem in windows application using c#
Posted 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 on: 26 Feb 2012  
Hey Swapnil.........

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

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

 eg....
        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)
               
Note:-
        this.Refresh();
function is used to Refresh the Components present on the CURRENT Windows Form.
        and not to refresh the Grid's DataSource...



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




Mayur B. Dighe:
If you help Someone without any Expectations, Somebody else will Definitely help you.

My Blog : ImmortalDotNET.BlogSpot.com

SPONSORED BY

Offshore Software and Database Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.