Monday, August 6, 2012

Update into mysql in C#

First of all we need to connect mysql via C# then update  data,
You know programming is very easy if you got the point like swimming in water,those who don't know how to swim then he will sink into water,but If you know how to swim then you will never sink.
Like the programming many student fall into love with programming because they know how to programming..
So don't worry just try to find out the point in programming.
Ok, lets come back to programming...
Some sample code will help you to update data to mysql with C#.



MySqlConnection con1;
            server = "localhost";
            database = "log_database";
            uid = "root";
            password = "";
            string connectionString;
            connectionString = "SERVER=" + server + ";" + "DATABASE=" +
            database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
            con1 = new MySqlConnection(connectionString);
            try
            {
                con1.Open();
             
                    string query = "UPDATE log_info SET Status='yes' WHERE UserName='" +"data" + "'";
                    MySqlCommand cmd2 = new MySqlCommand(query, con1);
                    cmd2.ExecuteNonQuery();
                    count++;


               
                con1.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

No comments:

Post a Comment