Solved

Auto populate MySql column on checkchanged event

Posted on 2015-02-18
2
54 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
Comment Utility
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
Comment Utility
That worked. Thanks for your help.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now