Esempio n. 1
0
        /// <summary>
        /// Loads an Item from Database
        /// </summary>
        /// <param name="connection">MySqlConnection</param>
        /// <param name="itemKeyname">Id_nb of the Item</param>
        /// <param name="databaseName">The name of the Database</param>
        /// <returns></returns>
        public ItemTemplates.ItemTemplateRow loadRowFromDatabase(MySqlConnection connection, string itemKeyname, string databaseName)
        {
            try
            {
                connection.Open();

                string columnsSQL = "";
                for (int i = 0; i < this.ItemTemplate.Columns.Count; i++)
                {
                    if (i != 0)
                    {
                        columnsSQL += ", ";
                    }

                    columnsSQL += "`" + this.ItemTemplate.Columns[i].ColumnName + "`";
                }
                string SQL = "SELECT " + columnsSQL + " FROM " + databaseName + " WHERE Id_nb = '" + itemKeyname + "' LIMIT 0,1";

                MySqlDataAdapter adapter = new MySqlDataAdapter();
                MySqlCommand     cmd     = new MySqlCommand();

                cmd.CommandText = SQL;
                cmd.Connection  = connection;

                adapter.SelectCommand = cmd;

                ItemTemplates tmp = new ItemTemplates();
                adapter.Fill(tmp.ItemTemplate);

                return((ItemTemplates.ItemTemplateRow)tmp.ItemTemplate.Rows[0]);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            finally
            {
                connection.Close();
            }

            return(this.ItemTemplate.NewItemTemplateRow());
        }
Esempio n. 2
0
        /// <summary>
        /// Loads an Item from Database
        /// </summary>
        /// <param name="connection">MySqlConnection</param>
        /// <param name="itemKeyname">Id_nb of the Item</param>
        /// <param name="databaseName">The name of the Database</param>
        /// <returns></returns>
        public ItemTemplates.ItemTemplateRow loadRowFromDatabase(MySqlConnection connection, string itemKeyname, string databaseName)
        {
            try
            {
                connection.Open();

                string columnsSQL = "";
                for (int i = 0; i < this.ItemTemplate.Columns.Count; i++)
                {
                    if (i != 0) columnsSQL += ", ";

                    columnsSQL += "`" + this.ItemTemplate.Columns[i].ColumnName + "`";
                }
                string SQL = "SELECT " + columnsSQL + " FROM " + databaseName + " WHERE Id_nb = '" + itemKeyname + "' LIMIT 0,1";

                MySqlDataAdapter adapter = new MySqlDataAdapter();
                MySqlCommand cmd = new MySqlCommand();

                cmd.CommandText = SQL;
                cmd.Connection = connection;

                adapter.SelectCommand = cmd;

                ItemTemplates tmp = new ItemTemplates();
                adapter.Fill(tmp.ItemTemplate);

                return (ItemTemplates.ItemTemplateRow)tmp.ItemTemplate.Rows[0];
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            finally
            {
                connection.Close();
            }

            return this.ItemTemplate.NewItemTemplateRow();
        }