Hi everybody.
I have a form which contains a user control.
When the form loads, I'm populating some DataSet, and assigning the dataset refernece to one of the control properties.
The control contains other control that are bound to various paths on that dataset, adding new rows, modifying, etc.
Now, I want to update the changes back to the database with dataadapters.
I can put a Update button on the control itself, or in the form containing it.
When I call the adapter's Update method in the context of the form (i.e. in response to form's button click), the db doesn't update.
When the same thing happens at the control, it updates as well.
It is important to mention, that both the form and the control contains the reference to the same dataset, and the ds contains the exaxct same information in both cases. (the rows has the same state, etc.)
.
Any help would be appriciated.
Thanks,
Yaakov

Databinding problem
grumpy3b
From what I see tilll now, is as somebody wrote upon, "databinding is the devil".
You don't have any control or idea when or why things happen. There is no documentation, too.
Thanks a lot for youe help. However, it seems I would need to replace the data model.
Yaakov
kasperstorm
http://support.microsoft.com/default.aspx scid=kb;en-us;Q313482
http://samples.gotdotnet.com/quickstart/winforms/doc/winformsdata.aspx
http://www.code-magazine.com/Article.aspx quickid=0409051
http://www.15seconds.com/issue/040614.htm
Joe
Leif Greenman
The same Update is done.
Here is the code. Sorry abbout the length, I didn't find a way do upload the files.
public partial class RequestEditor : UserControl
{
BudgetDataSet dataSource;
public BudgetDataSet DataSource
{
get { return dataSource; }
set
{
if (value == null)
throw new ArgumentNullException("dataSoucre");
dataSource = value;
BindControls();
}
}
public int RowIndex
{
get { return requestBindingSource.Position; }
set
{
if (dataSource == null)
throw new ArgumentException("DataSource is not defined");
requestBindingSource.Position = value;
}
}
public RequestEditor()
{
InitializeComponent();
dtpDate.Value = DateTime.Now;
dgvDetails.AutoGenerateColumns = false;
}
public void AddNew()
{
requestBindingSource.AddNew();
dtpDate.Value = DateTime.Now;
}
public void Save()
{
requestBindingSource.EndEdit();
//***************************************
//-- When I do it here, the data updates as well, perfectly
//I'm commmenting the update lines in the form when I uncommenting this, of course.
//new RequestTableAdapter.Update(DataSource.Request);
//new RequestDetailTableAdapter().Update(DataSource.RequestDetail);
//new RequestTargetsTableAdapter().Update(DataSource.RequestTargets);
}
public void Cancel()
{
requestBindingSource.CancelEdit();
}
private void BindControls()
{
applicantsBindingSource.DataSource = DataSource;
productBindingSource.DataSource = DataSource;
targetBindingSource.DataSource = DataSource;
requestBindingSource.DataSource = DataSource;
}
}
partial class RequestForm : Form
{
RequestEditor re;
public RequestForm()
{
InitializeComponent();
re = new RequestEditor();
re.Dock = DockStyle.Fill;
Controls.Add(re);
}
private void RequestEditForm_Load(object sender, EventArgs e)
{
budgetDataSet.EnforceConstraints = false;
this.productTableAdapter.Fill(this.budgetDataSet.Product);
this.targetTableAdapter.Fill(this.budgetDataSet.Target);
this.applicantsTableAdapter.Fill(this.budgetDataSet.Applicants);
re.DataSource = budgetDataSet;
re.AddNew();
}
protected override void OnClosing(CancelEventArgs e)
{
re.Save(); //calls requestBindingSource.EndEdit() on re.
//------ here it doesn't work, only the Request row is updated, partially.
//In partially I mean that not all control values are returned to the dataSource.
new RequestTableAdapter.Update(budgetDataSet.Request);
new RequestDetailTableAdapter().Update(budgetDataSet.RequestDetail);
new RequestTargetsTableAdapter().Update(budgetDataSet.RequestTargets);
}
}
slimbim
Can you post sample code the demonstrates the issue
Thanks,
Joe
Semyon P
So, please tell me how can I upload the files. You can look at them and tell me what is wrong.
Yaakov
MetroP
I mixed up things in the copy-paste proccess.
I fixed the attached code, so please have a second look.
In addition, here is some more details:
In the requestEditor, I have few controls bound to the current (or new) Request row (like DateTimePicker, text box and more), a datagridView bound to RequestDetails binding source (which is in turn bound to the FK_RequestDetails_Request relation), and a Listbox bounded to RequestTargets bindingsource, which is another 'slave' table of Request.
Thanks again, and sorry for the english.. (I'm not an american).
Yaakov
RussellReed
Thanks,
Joe
http://lab.msdn.microsoft.com/vs2005/
David Broman
I know the basic implementatuin, features, and the new "cool stuff in .Net 2.0", and that is the only thing those articles describe. I read them, and more.
None of them is explaining what's going on behind the scenes, and it seems nobody knows.
When it comes to simple behaviors, databinding is great. When the app goes a little bit different from MS in-mind, things goes mad. Yes, Drag-Once (and mess with it forever).
I wonder if MS guys ever wrote a real world Win-app using their own tools.
Yaakov
deval bhavsar
I don't see anything obvious however I'm guessing it has something to do with how/when the data is committed or exceptions being thrown during the commit. Does is still repro if you scale back the Request Editor to just the RequestRow If so, remove the DateTimePicker and see if it still repros
Joe
ryanlcs
Thanks,
Joe
mr pitiful
Our design time and runtime is not perfect nor is it easy to understand. There are conceptual issues you'll need to overcome to understand how it works. I'm trying to work with you to help you overcome those conceptual hurdles.
Joe