Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Auto populate MySql column on checkchanged event

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
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 Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

670 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