Ejemplo n.º 1
0
        /// <summary>l um valor</summary>
        internal static int executeNonQuery( string query )
        {
            string connectionString = OrionGlobals.getConnectionString("connectiostring-mysql");
            MySqlConnection conn = new MySqlConnection(connectionString);

            try {
                conn.Open();

                MySqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = query;
                cmd.CommandType = CommandType.Text;

                object obj = cmd.ExecuteScalar();
                if( obj == null ) {
                    return 0;
                }
                return int.Parse(obj.ToString());

            } catch( Exception e ) {
                Chronos.Utils.Log.log("Connection String: {0}", connectionString);
                Chronos.Utils.Log.log("Error: " + e.Message);
                throw;
            } finally {
                conn.Close();
            }
        }
Ejemplo n.º 2
0
Archivo: List.cs Proyecto: jhogan/qed
 public CatLists(MySqlConnection conn)
 {
     _conn = conn;
     conn.Open();
     ArrayList listNames = new ArrayList();
     MySqlCommand cmd = conn.CreateCommand();
     cmd.CommandText ="SELECT DISTINCT ListName FROM " + _table;
     MySqlDataReader dr = cmd.ExecuteReader();
     while(dr.Read()) {
         listNames.Add(Convert.ToString(dr["ListName"]));
     }
     dr.Close();
     conn.Close();
     foreach(string listName in listNames){
         List.Add(new CatList(listName, false, conn));
     }
 }
Ejemplo n.º 3
0
		/// <summary>
		/// Executes a single command against a MySQL database.
		/// </summary>
		/// <param name="connectionString">Settings to use for this command</param>
		/// <param name="commandText">Command text to use</param>
		/// <param name="commandParameters">Array of <see cref="MySqlParameter"/> objects to use with the command</param>
		/// <returns><see cref="MySqlDataReader"/> object ready to read the results of the command</returns>
		public static MySqlDataReader ExecuteReader(string connectionString, string commandText, params MySqlParameter[] commandParameters)
		{
			//create & open a SqlConnection
			MySqlConnection cn = new MySqlConnection(connectionString);
			cn.Open();

			try
			{
				//call the private overload that takes an internally owned connection in place of the connection string
				return ExecuteReader(cn, null, commandText, commandParameters, false );
			}
			catch
			{
				//if we fail to return the SqlDatReader, we need to close the connection ourselves
				cn.Close();
				throw;
			}
		}
Ejemplo n.º 4
0
		/// <summary>
		/// Updates the given table with data from the given <see cref="DataSet"/>
		/// </summary>
		/// <param name="connectionString">Settings to use for the update</param>
		/// <param name="commandText">Command text to use for the update</param>
		/// <param name="ds"><see cref="DataSet"/> containing the new data to use in the update</param>
		/// <param name="tablename">Tablename in the dataset to update</param>
		public static void UpdateDataSet( string connectionString, string commandText, DataSet ds, string tablename )
		{
			MySqlConnection cn = new MySqlConnection( connectionString );
			cn.Open();
			MySqlDataAdapter da = new MySqlDataAdapter( commandText, cn );
			MySqlCommandBuilder cb = new MySqlCommandBuilder( da );
			da.Update( ds, tablename );
			cn.Close();
		}