Hello all,
I am at it again this time incorporating MySQL database into C# code using Visual Studio 2008 first off the textboxes are databinded using details view...
the issue at the moment is trying to not make bulky code and compare the value of txtDealName.text and mtxtDealNum2.text to what is in the Database
Here is my code for the button so far:
private void btnSavDealer_Click(object sender, EventArgs e)
{
//Create Database connection
MySqlConnection conn = new MySqlConnection("server=localhost;user id=root;Password=666mysql69;persist security info=True;database=central1;");
string query = "SELECT * FROM dealer WHERE DealNum = '" + lblDealNum2.Text + "'";
MySqlCommand cmd1 = new MySql.Data.MySqlClient.MySqlCommand(query);
if (txtDealName.Text == "")
{
MessageBox.Show("You must enter a name for this Dealer.");
txtDealName.Focus();
txtDealName.SelectAll();
return;
}
else if (txtDealName.Text == cmd1.
else
{
//MessageBox.Show(txtDealName.Text);
string query = "UPDATE dealer SET DealName = '" + txtDealName.Text + "' WHERE DealNum = '" + lblDealNum2.Text + "'";
MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand(query);
try
{
conn.Open();
cmd.Connection = conn;
cmd.ExecuteNonQuery();
}
catch (MySqlException)
{
System.Diagnostics.Debugger.Break();
}
}
if (mtxtDealPhone2.Text == "" || mtxtDealPhone2.Text.Length == 12)
{
//MessageBox.Show(mtxtDealPhone2.Text);
string query = "UPDATE dealer SET DealPhone2 = '" + mtxtDealPhone2.Text + "' WHERE DealNum = '" + lblDealNum2.Text + "'";
MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand(query);
try
{
cmd.Connection = conn;
cmd.ExecuteNonQuery();
}
catch (MySqlException)
{
System.Diagnostics.Debugger.Break();
}
}
else
{
MessageBox.Show("You need to enter a full phone number with area code for your Secondary number.");
mtxtDealPhone2.Focus();
mtxtDealPhone2.SelectAll();
return;
}
this.Close();
}
problem is I have about 20 fields to validate and if the values are the same i do not want it to write to the database that field...