Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 04-12-08   #1 (permalink)
XM Channel 51 - 24/7
 
afzsom's Avatar
 
intel nvidia

Join Date: Jun 2007
Location: West Palm Beach, FL
Posts: 4,209

Rep: 565 afzsom is becoming famousafzsom is becoming famousafzsom is becoming famousafzsom is becoming famousafzsom is becoming famousafzsom is becoming famous
Unique Rep: 341
Trader Rating: 8
Default C# Windows Form w/ Database

Having a wee bit of an issue with inserting a new record into a database. I've done this sort of thing before but on a ASP.NET web page, but somehow the code fails to work when its in a Windows GUI Form environment. Attached is the section of code that runs when the button is clicked. I've also started another thread on the MSDN forums, I've explained a bit more there as well.

Code:
        
private void uploadButton_Click(object sender, EventArgs e)
        {
            if (nameText.Text == "" || emailText.Text == "" || cityText.Text == "" || stateText.Text == "" || zipText.Text == "")
            {
                statusLabel.ForeColor = Color.Red;
                statusLabel.Text = "Failed!";
            }
            else
            {
                try
                {
                    string email = emailText.Text;
                    ValidationTableAdapters.ComputersTableAdapter vAdapter = new ValidationTableAdapters.ComputersTableAdapter();
                    Validation.ComputersDataTable vTable = vAdapter.CheckComputer(email);
                    if (vTable.Rows.Count == 1)
                    {
                        MessageBox.Show("Sorry, a validation with that email already exists.");
                        statusLabel.Text = "";
                        emailText.Focus();
                    }
                    else
                    {
                        ValidationTableAdapters.ComputersTableAdapter adapter = new Database.ValidationTableAdapters.ComputersTableAdapter();
                        Validation.ComputersDataTable Computers = adapter.GetComputers();
                        Validation.ComputersRow newRow = Computers.NewComputersRow();

                        newRow.Name = nameText.Text;
                        newRow.Email = emailText.Text;
                        newRow.City = cityText.Text;
                        newRow.State = stateText.Text;
                        newRow.Zip = zipText.Text;

                        Computers.AddComputersRow(newRow);
                        adapter.Update(Computers);
                        Computers.AcceptChanges();

                        statusLabel.ForeColor = Color.Black;
                        statusLabel.Text = "Success!";
                    }
                }
                catch
                {
                    MessageBox.Show("Sorry, unable to process your request at this time.");
                }
            }
        }
__________________
Watercooling Loop: MCP655 Vario -> Black Ice GTX360 -> D-Tek FuZion V1 -> MCW-60 -> MicroRes
Loop Cost: $395.03


System: R'lyeh
CPU
E6600 (L631F) @ 3.6GHz 1.425v (lapped)
Motherboard
ASUS P5B-E
Memory
2GB Corsair PC2-6400 CAS5
Graphics Card
BFG Tech 8800GTS OC 640MB
Hard Drive
320GB WD Caviar 7200
Sound Card
Audigy 4
Power Supply
SeaSonic S12 550W
Case
Lian-Li V2000
CPU cooling
D-TEK FuZion V1
GPU cooling
MCW60
OS
Windows XP Professional SP3
Monitor
Samsung 226BW
afzsom is offline Overclocked Account afzsom's Gallery   Reply With Quote
Old 04-12-08   #2 (permalink)
Programmer
 
Licht's Avatar
 
amd ati

Join Date: Mar 2007
Location: Bel Air
Posts: 8,240
Blog Entries: 3

Rep: 234 Licht is acknowledged by manyLicht is acknowledged by manyLicht is acknowledged by many
Unique Rep: 157
Trader Rating: 0
Default

If i beg will this thread get more posts?

System: AMD-AMD-ATI
CPU
AMD Athlon X2 5200+
Motherboard
Gigabyte 790X AM2+
Memory
2x 1Gb Kingston && 2x 1Gb Wintec
Graphics Card
Saphire HD 3870
Hard Drive
[RAID0] [2X] WD 160GB 7,200RPM
Sound Card
X-Fi Extreme Gamer Fatality Professional
Power Supply
OCZ Game-X-Stream 700w
Case
NZXT Black Steel
CPU cooling
Stock Heatskin & Fan
GPU cooling
Stock Saphire 3870 Cooling
OS
Windows Vista Home Premium x64 SP1
Monitor
Samsung SyncMaster 19" Widescreen
Licht is online now Licht's Gallery   Reply With Quote
Old 04-12-08   #3 (permalink)
Performance...
 
linskingdom's Avatar
 
intel nvidia

Join Date: Jun 2007
Location: In Office
Posts: 8,374

Rep: 2074 linskingdom is a legendlinskingdom is a legendlinskingdom is a legendlinskingdom is a legendlinskingdom is a legendlinskingdom is a legendlinskingdom is a legendlinskingdom is a legendlinskingdom is a legendlinskingdom is a legendlinskingdom is a legend
Unique Rep: 897
Trader Rating: 3
Default

I think two things can give try.

1. Take out the Computers.AcceptChanges(). Sometime, once use this, DataRowState will be reset.
2. Add an unique ID column to the table. Assign it with unique ID. Check duplicated record with email and name but not the ID.

System: QD65D45
CPU
65Q/D&45D
Motherboard
DFI/Asus/Gigabyte
linskingdom is offline Overclocked Account linskingdom's Gallery   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 12:17 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.13321 seconds with 9 queries