Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Data Problem / Committal
 

Data Problem / Committal

Hi,

I'm having a problem getting my datasource (SQL Server 2005) to committ changes. I think I'm probably not close() or dispose() correctly, but I'm not sure. Here's what I have:

I have a form (frmList) that contains a list of data from a database table (tblData). I also have a form that I can enter the data into (frmData). It's loaded as a dialog window.

Basically, frmList loads and displays all the records from tblData. When I click on a button, frmData loads. When frmData loads, it creates a record in the database, binds it to frmData. I have a Dataset, tableadapter, binding source etc. all setup on frmData. In the FormClosing() method of frmData, I call a Load_Items() method on frmList to populate the list.

When I call the Load_Items() method from frmData, the newest item doesn't show up right away. I created a button on frmList that calls the exact same load_items method. If I close frmData (the data doesn't show up), but if I click the button, it does. I thought maybe there was a committ delay, so I waited 1 second and that didn't work either.

I'm thinking there is a command / method that is not committing the changes until I close the form..... anyone know what that is?

I'm disposing all connections, DS, BS, TA, etc.

Here's my FormClosing() code:

bsItems.EndEdit()

tatblData.Update(dsData.tblData)

tatblData_Property.Dispose()

bsItems_Property.Dispose()

dsData_Property.Dispose()

frmList.Load_Items()

TIA,

John

johnrou  Monday, April 07, 2008 5:18 PM
It appears, after some exhaustive tests that problem may not be with data committal. I did add in a couple of Dispose() calls that I forgot, but that wasn't the problem.

I'm still not sure where the problem is, but it appears that the data is committed after the TableAdapter.Update() statement executes.

If it matters, I'm Dispose() my objects backward... like this:

BindingSource.Dispose()
TableAdapter.Dispose()
DataSet.Dispose()

I'll repost in another thread to talk about the remaining issue.

John
johnrou  Saturday, April 12, 2008 4:49 AM

Hi johnrou,

Based on my understanding, you want to update your frmList Form from another Form named frmData, but it dose not work, but you try to update the data in frmList directly by clicking a button name update, it works fine. If I have misunderstood you please feel free to tell me, thanks.

First of all, try to check whether the code used to update frmList in the Form frmData has been called correctly. You can check this by inserting break point at the methodfrmList.Load_Items() statement. And then press F10 to execute step by step.

I have just tested this situation, but it works fine. The textBox in frmList has been updated from frmData.

code in frmData:

Code Snippet

private FormList frmList;

public FromData (FormList frmList)

{

this.frmList = frmList;

FormClosingEventHandler(FormData_FormClosing);

}

void FromData_FormClosing(object sender, FormClosingEventArgs e)

{

frmList.SetText("Hello");

}

code in frmList:

Code Snippet

private void button1_Click(object sender, EventArgs e)

{

FromData frmData = new Form2(this);

frmData.Show();

}

public void SetText(string x)

{

this.myTextBox1.Text = x;

}

Hope this can be helpful !

Regards,

Roy Zhou

Roy Zhou - MSFT  Friday, April 11, 2008 7:52 AM

That's not quite the problem. Frm Data is updating data in a database. I cannot get those changes to appear in my frm List.

For example: frmList contains a list of names. When I double-click a name, frmData appears with the information about a person. I can update the information, then close the form. I make a call to frmList to clear itself and reload from the database. The changes I just made in frmData aren't showing up.

If I re-execute the refresh a frmList, it works fine. It's almost as if the changes to the datasource aren't committing right away. I need them to commit as soon as I execute the TableAdapter.Update() statement. (Which I thought was when it's updated).

John

johnrou  Friday, April 11, 2008 2:33 PM
It appears, after some exhaustive tests that problem may not be with data committal. I did add in a couple of Dispose() calls that I forgot, but that wasn't the problem.

I'm still not sure where the problem is, but it appears that the data is committed after the TableAdapter.Update() statement executes.

If it matters, I'm Dispose() my objects backward... like this:

BindingSource.Dispose()
TableAdapter.Dispose()
DataSet.Dispose()

I'll repost in another thread to talk about the remaining issue.

John
johnrou  Saturday, April 12, 2008 4:49 AM

You can use google to search for other answers

Custom Search

More Threads

• dgv.CurrentCell.Cells["DisCount"].EditedFormattedValue && dgv.CurrentCell.Cells["Discount].Value ?
• Getting information out of a Datagridview
• ComboBox DataSource with dbnull.value prevents binding to SelectedValue
• updating the database
• Change DataGridView Datasource while keeping selected row
• Using SqlCeResultSet to insert and it doesnt insert (no errors)
• Adding default cell values
• DataGridView unbound column not updated.
• Data Relations not working please help
• Problem with DataGridView AutoResizeRows -> Possible Bug?