|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
C# Windows Form w/ Database
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
XM Channel 51 - 24/7
Join Date: Jun 2007
Location: West Palm Beach, FL
Posts: 4,209
Rep: 565
![]() ![]() ![]() ![]() ![]() ![]() Unique Rep: 341
Trader Rating: 8
|
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
|
|||||||||||||
|
|
|
|
#2 (permalink) | |||||||||||||
|
Programmer
|
If i beg will this thread get more posts?
__________________
|
|||||||||||||
|
|
|
|
#3 (permalink) | |||
|
Performance...
|
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.
__________________
Push the limit one more time ... ![]()
|
|||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|