Solved

Auto populate MySql column on checkchanged event

Posted on 2015-02-18
2
72 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

623 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