By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,446 Members | 2,998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,446 IT Pros & Developers. It's quick & easy.

Databound text box does not update database

P: n/a
I have a fairly simple form with databound text boxes, but changes (or new
records) are not recognized. The text boxes are successfully populated with
data (from the database) and I can cycle through all the records. Using a
datagrid works fine for updating.

I've based this on the first sample project from the book "C# Professional
Projects" (Premier Press). I've read many posts concerning this (and the MS
KB as well), and most seem to say that databound text boxes must use a
DataRow object (in addition to connection, data adapter, and dataset
objects), and therefore not as simple as a datagrid.

Based on what I've read, I'm inclined to believe that the book is wrong.
Here are the code fragments for loading and saving the data:
private void btnEdit_Click (object sender, System.EventArgs e)
{
customerDataSet.Clear();
sqlDataAdapter1.Fill(customerDataSet);
// . . .
}

private void btnSave_Click (object sender, System.EventArgs e)
{
// seems simple enough, but doesn't work (for databound text boxes),
works for datagrid
sqlDataAdapter1.Update (customerDataSet);
}

If the book is indeed wrong, I plan to still work through the projects (as
idea generators) but use "Programming C#" (Liberty) for support, which seems
like a better book.

Incidentally, I've had other problems with the "C# Professional Projects"
book (the underlying database for the above project is assumed to exist and
be accessible, but no details given). Then again, being new to .NET and C#,
I may be missing something obvious. Anyone else have issues with this book?

Any constructive help is much appreciated,

Patrick


Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hello Patrick,

The code snippets you've provided are OK. The problem is most likely in that
you have to force the databinding framework to puch the updated values from
the bound controls to the underlying datasource. This is done automatically
when you change the current record, but this might be not the case in your
program. So, try the following before calling the Save method:

CurrencyManager cm = (CurrencyManager)this.BindingContext[myDataSource, "<my
data member here>"];
cm.EndCurrentEdit();

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Patrick Demets" <no*************@HATESPAMshaw.ca> wrote in message
news:UQe%b.617848$X%5.187676@pd7tw2no...
I have a fairly simple form with databound text boxes, but changes (or new
records) are not recognized. The text boxes are successfully populated with data (from the database) and I can cycle through all the records. Using a
datagrid works fine for updating.

I've based this on the first sample project from the book "C# Professional
Projects" (Premier Press). I've read many posts concerning this (and the MS KB as well), and most seem to say that databound text boxes must use a
DataRow object (in addition to connection, data adapter, and dataset
objects), and therefore not as simple as a datagrid.

Based on what I've read, I'm inclined to believe that the book is wrong.
Here are the code fragments for loading and saving the data:
private void btnEdit_Click (object sender, System.EventArgs e)
{
customerDataSet.Clear();
sqlDataAdapter1.Fill(customerDataSet);
// . . .
}

private void btnSave_Click (object sender, System.EventArgs e)
{
// seems simple enough, but doesn't work (for databound text boxes),
works for datagrid
sqlDataAdapter1.Update (customerDataSet);
}

If the book is indeed wrong, I plan to still work through the projects (as
idea generators) but use "Programming C#" (Liberty) for support, which seems like a better book.

Incidentally, I've had other problems with the "C# Professional Projects"
book (the underlying database for the above project is assumed to exist and be accessible, but no details given). Then again, being new to .NET and C#, I may be missing something obvious. Anyone else have issues with this book?
Any constructive help is much appreciated,

Patrick


Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.