473,326 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Databound text box does not update database

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
1 9522
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jon S via DotNetMonster.com | last post by:
Hi all I'm new to C# and ADO.Net. I've managed to insert, update and delete records from a database but I need to know how to show these changes immediately. For example : If I delete a record...
4
by: John Rose | last post by:
I have one databound TextBox on a page with one button. The TextBox loads the correct SQL record data but typing a new string into the Textbox fails to change the DataSet. Any ideas? There must...
0
by: Coco | last post by:
Hi, who knows how to update the 'child' textboxes in a datarelated situation if the child records "doesn't yet exitsts/are still empty"? The problem can be explained with the Northwind database....
0
by: Benny Dein | last post by:
Hi A newbie question regarding using update function on sqldataadapter: I have created a connection, a dataadapter and a dataset on my webform. I have put a texbox on my webform to show a...
9
by: Jakob Lithner | last post by:
1) I have a DataGridView with edit capability. But in some columns I want to limit the input with a DropDownList. There is no inbuilt column for DropDownLists so I intended to add one myself. I...
2
by: shumaker | last post by:
I have a combobox that is very much like the one found in the RSS project here: http://msdn.microsoft.com/vstudio/express/visualCSharp/learning/ My projectNameComboBox basically is filled with a...
3
by: Jeff | last post by:
hey asp.net 2.0 I want to programmatically populate (with data from the database) a label control in a FormView on a webpage. Is it a good idea to put my logic inside the DataBound event of...
2
by: KerryL | last post by:
How do I update the value of a databound column within my datagrid from within the SelectedIndexChanged event of a dropdownlist, also found within my datagrid? I believe I need to determine the...
0
by: Mike | last post by:
So here's the situation (.NET 2.0 btw): I have a form, and on this form is a textbox among many other databound controls. The textbox is bound to a field in a data table via the Text property. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.