/// <summary>
 /// Executes a query without a return. 27/11/15
 /// </summary>
 private static bool ExecuteNonQuery(string query)
 {
     if (connectionOpen())
     {
         // Creates a database command from the query and existing connection
         OdbcCommand cmd = new OdbcCommand(query, connection);
         try
         {
             cmd.ExecuteNonQueryAsync(); // Executes the command
             return true;
         }
         catch (OdbcException ex)
         {
             // Displays an error if something bad occurs while executing the command
             error = ex.Message;
             return false;
         }
     }
     else
     {
         return false;
     }
 }
Exemple #2
0
        private void fixAllNames(object state)
        {
            try
            {
                if (!CanConnect)
                    return;
                using (OdbcCommand comID = new OdbcCommand("select distinct Id from trafikverket.weather where isnull(MeasurePoint);", MySqlConnection))
                {
                    using (OdbcDataReader drID = comID.ExecuteReader())
                    {
                        string strUpdateText = "";
                        while (drID.Read())
                        {
                            Thread.Sleep(100);
                            if (bAbort)
                                return;
                            string strId = drID.GetString(0);

                            using (OdbcCommand comName = new OdbcCommand("select distinct MeasurePoint from trafikverket.weather where Id='" + strId + "' and not isnull(MeasurePoint);", MySqlConnection))
                            using (OdbcDataReader drName = comName.ExecuteReader())
                            {
                                if (drName.Read())
                                {
                                    string strName = drName.GetString(0);
                                    strUpdateText += "update trafikverket.weather set MeasurePoint='" + strName + "' where Id='" + strId + "' and isnull(MeasurePoint);\r\n";
                                }
                            }
                        }
                        if (!string.IsNullOrEmpty(strUpdateText))
                        {
                            try
                            {
                                using (OdbcCommand updateName = new OdbcCommand(strUpdateText, MySqlConnection))
                                    updateName.ExecuteNonQueryAsync();

                            }
                            catch
                            {

                            }
                        }
                    }
                }
            }
            catch { }
        }