Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 24th, 2006, 11:38 PM
Authorized User
 
Join Date: Apr 2006
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...
 
Old April 25th, 2006, 04:05 PM
Authorized User
 
Join Date: Mar 2006
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
 
Old April 25th, 2006, 11:24 PM
Authorized User
 
Join Date: Apr 2006
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.
 
Old April 26th, 2006, 05:53 AM
Authorized User
 
Join Date: Apr 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old April 26th, 2006, 04:45 PM
Authorized User
 
Join Date: Apr 2006
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.
 
Old April 26th, 2006, 06:19 PM
Authorized User
 
Join Date: Apr 2006
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.





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 02:31 PM
ch15: can't get JSTL to be recognized brownale2k JSP Basics 1 August 8th, 2003 04:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.