Solved

Auto populate MySql column on checkchanged event

Posted on 2015-02-18
2
67 Views
Last Modified: 2015-02-19
I'm trying to add text to an status field if the failed checkbox is selected. Here is the method:
 public static bool falseOrder(string status)
    {
        {

            using (MySqlConnection connection = new MySqlConnection("server=***;user id=***;database=***;password=***;persistsecurityinfo=True"))
            {
                try
                {
                    connection.Open();
                    string query = "Insert into Order (status) values (@status);";

                    // set the command text of the command object0
                    using (MySqlCommand cmd = new MySqlCommand(query, connection))
                    {

                        cmd.Parameters.AddWithValue("@status", status);


                        status = "Failed";
                        cmd.ExecuteNonQuery();
                        connection.Close();
                        return true;

                    }
                }
                catch (Exception ex) // <-- Catch the generic type, which should INCLUDE MySQL exceptions
                {
                    // Store the exception for later
                    lastException = ex;

                    return false;

                }

            }

        }
    }
}

Open in new window


Here is the code for the event:
 protected void cbPass0_CheckedChanged(object sender, EventArgs e)
            
        {
            if (cbPass0.Checked == true)
            {
                lblQC.Visible = true;
                txtQC.Visible = true;
                clsDataLayer.falseOrder(status); 

            }

Open in new window


It's not populating the status field. Any ideas on what i'm doing wrong?
0
Comment
Question by:Robin Harris
2 Comments
 
LVL 14

Accepted Solution

by:
Lokesh B R earned 500 total points
ID: 40618274
Hi,

try this

public static bool falseOrder(string status)
    {
        {

            using (MySqlConnection connection = new MySqlConnection("server=***;user id=***;database=***;password=***;persistsecurityinfo=True"))
            {
                try
                {
                    connection.Open();
                    string query = "Insert into Order (status)  values (@status);";

                    // set the command text of the command object0
                    using (MySqlCommand cmd = new MySqlCommand(query, connection))
                    {
                        status = "Failed";
                        cmd.Parameters.AddWithValue("@status", status);
                        cmd.ExecuteNonQuery();
                        connection.Close();
                        return true;
                    }
                }
                catch (Exception ex)
                {
                    // Store the exception for later
                    lastException = ex;

                    return false;

                }

            }

        }
    }
}

Open in new window

0
 

Author Comment

by:Robin Harris
ID: 40619162
That worked. Thanks for your help.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question