Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Auto populate MySql column on checkchanged event

Posted on 2015-02-18
2
Medium Priority
?
95 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 15

Accepted Solution

by:
Lokesh B R earned 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

916 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