Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 24th, 2006, 11:38 PM
Authorized User
 
Join Date: Apr 2006
Location: , , Canada.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default Database changes not recognized until restart

Hello! I'm a newb, especially to databases, so bear with me. I'm writing a program which, ultimately, takes the value of textboxes and writes them to the database. The code to accomplish this is below. However, the changes don't seem to appear in the combobox (which contains all of the entries for a specific column of data) until after the application is restarted. Why is this? Thank-you in advance.

-----------------------------
        private void btnSave_Click(object sender, EventArgs e)
        {
            //Put textbox values into variables
            string txtMakeValue = txtMake.Text;
            string txtModelValue = txtModel.Text;
            int txtYearValue = Convert.ToInt32(txtYear.Text);
            double txtMileageValue = Convert.ToDouble(txtCurrentMileage.Text);

            //Create new row and fill in data
            VehiclesDataSet.CarsRow newCarsRow = vehiclesDataSet1.Cars.NewCarsRow();
            newCarsRow.Make = txtMakeValue;
            newCarsRow.Model = txtModelValue;
            newCarsRow.Year = txtYearValue;
            newCarsRow.Mileage = txtMileageValue;

            //Add new row
            vehiclesDataSet1.Cars.Rows.Add(newCarsRow);
            carsTableAdapter1.Update(newCarsRow);
        }

Computers will never surpass the human brain; no computer will ever be able to replicate human stupidity.
__________________
If only computers could write programs themselves...
Reply With Quote
  #2 (permalink)  
Old April 25th, 2006, 04:05 PM
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here are some suggestions
Try calling the AcceptChanges method of the dataset

vehiclesDataSet1.Cars.Rows.Add(newCarsRow);
vehicleDataSet1.Cars.AcceptChanges();
(Dont know if u would need to call the carsTableAdapter1.Update(newCarsRow); manually in that case).

Lemme know if this helps


Sreeram
Reply With Quote
  #3 (permalink)  
Old April 25th, 2006, 11:24 PM
Authorized User
 
Join Date: Apr 2006
Location: , , Canada.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by sreeramv
Lemme know if this helps
With or without the Update method, I still need to restart the application to have the changes reflected in the combobox. However, I appreciate your help! Please give me any ideas you have!

Computers will never surpass the human brain; no computer will ever be able to replicate human stupidity.
Reply With Quote
  #4 (permalink)  
Old April 26th, 2006, 05:53 AM
Authorized User
 
Join Date: Apr 2006
Location: , , .
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Set DataSource and bind your dropdown again after this operation...

Reply With Quote
  #5 (permalink)  
Old April 26th, 2006, 04:45 PM
Authorized User
 
Join Date: Apr 2006
Location: , , Canada.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, I'm new. I used the Property window to set these options originally. Could you give an example of how to do this in code? My guess was to add

            this.cbxCurrentVehicle.DataSource = this.carsBindingSource;
            this.cbxCurrentVehicle.DisplayMember = "Model";
            this.cbxCurrentVehicle.ValueMember = "CarID";

but that doesn't seem to work.

Computers will never surpass the human brain; no computer will ever be able to replicate human stupidity.
Reply With Quote
  #6 (permalink)  
Old April 26th, 2006, 06:19 PM
Authorized User
 
Join Date: Apr 2006
Location: , , Canada.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually, never mind, I was playing around and got it! Here is what works. I used the AcceptChanges(); method, as well as:

                this.carsTableAdapter1.Fill(this.vehiclesDataSet1. Cars);
                this.cbxCurrentVehicle.DataSource = this.carsBindingSource;
                this.cbxCurrentVehicle.DisplayMember = "Model";
                this.cbxCurrentVehicle.ValueMember = "CarID";

Thank-you so much everyone! Your help is greatly appreciated. I will be back once I am more experienced to help others!

Computers will never surpass the human brain; no computer will ever be able to replicate human stupidity.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ruby is not recognized.... Crippy RoR Ruby on Rails 1 July 16th, 2008 08:37 AM
not recognized nachtegaal9999 ASP.NET 1.0 and 1.1 Basics 0 April 25th, 2006 02:04 PM
MSXSL is not recognized as an internal or external GLSmyth XML 2 October 6th, 2005 10:36 AM
'net' is not recognized as a command ababb BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 7 December 20th, 2004 01:31 PM
ch15: can't get JSTL to be recognized brownale2k JSP Basics 1 August 8th, 2003 04:32 PM



All times are GMT -4. The time now is 03:52 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.