Beispiel #1
0
 public void InsertKeyRow(string tablename, StoredAttribute keyentry)
 {
     try
     {
         MySqlCommand odbccommand = new MySqlCommand("INSERT IGNORE INTO "
                                                     + tablename
                                                     + " ("
                                                     + keyentry.name
                                                     + ") VALUES ( ? )", connection);
         odbccommand.Parameters.Add(new MySqlParameter(@"@" + keyentry.name, keyentry.type)).Value = keyentry.GetString();
         DoQuery(odbccommand);
     }
     catch (Exception ex)
     {
         throw new Exception("Error with key value " + keyentry.GetString() + " for column " + keyentry.name + ": " + ex.Message);
     }
 }
Beispiel #2
0
        protected List <Hashtable> Select(string tablename, StoredAttribute keyatt, bool selectall)
        {
            MySqlDataReader  myReader;
            DataTable        dt       = new DataTable();
            List <Hashtable> hashlist = new List <Hashtable>();

            try
            {
                string commandstr = "SELECT * FROM " + tablename;
                if (!selectall)
                {
                    commandstr += " WHERE " + keyatt.name + "= ? ";
                }

                MySqlCommand odbccommand = new MySqlCommand(commandstr, connection);

                if (!selectall)
                {
                    odbccommand.Parameters.Add(new MySqlParameter(@"@" + keyatt.name, keyatt.type)).Value = keyatt.GetString();
                }

                // load to dt
                myReader = odbccommand.ExecuteReader();
                dt.Load(myReader);

                // actually let's make it a list of hashtables
                hashlist = Util.convertDataTableToHashTables(dt);
                myReader.Close();
            }
            catch (Exception ex)
            {
                throw new Exception("Error with key value " + keyatt.GetString() + " for column " + keyatt.name + ": " + ex.Message);
            }

            // I'll deal with the connection later if I remember.  I probably won't remember.
            myReader.Close();

            return(hashlist);
        }
Beispiel #3
0
        public void UpdateRow(string tablename, StoredAttribute keyentry, List <StoredAttribute> attlist)
        {
            string eqstring = "";

            attlist.Remove(keyentry);
            foreach (StoredAttribute att in attlist)
            {
                if (eqstring.Length > 0)
                {
                    eqstring = eqstring + ",";
                }
                eqstring = eqstring + att.name + "= ? ";
            }
            try
            {
                MySqlCommand odbccommand = new MySqlCommand("UPDATE " + tablename + " SET " + eqstring + " WHERE " + keyentry.name + "= ?", connection);
                foreach (StoredAttribute att in attlist)
                {
                    odbccommand.Parameters.Add(new MySqlParameter(@"@" + att.name, att.type)).Value = att.GetString();
                }
                //odbccommand = AddParameters( odbccommand, rowdict );
                //odbccommand.Parameters.AddWithValue( "@sqlname", keyentry.SqlName );
                //odbccommand.Parameters.AddWithValue( "?keyval", keyentry.value );
                odbccommand.Parameters.Add(new MySqlParameter(@"@" + keyentry.name, keyentry.type)).Value = keyentry.GetString();
                DoQuery(odbccommand);
            }
            catch (Exception ex)
            {
                throw new Exception("Error with updating row " + keyentry.ToString() + " in table " + tablename + ": " + ex.Message);
            }
        }