예제 #1
0
        private void UpdateInDatabase(MySqlConnection con)
        {
            // Assert(FieldID > 0);
            string strCommandText = string.Format(@"UPDATE TargetFormFields SET TargetID={0}, FieldName={1}, FieldValue={2} WHERE FieldID={3};",
                                                  TargetID,
                                                  MySqlUtils.RawStringToDatabaseString(FieldName),
                                                  MySqlUtils.RawStringToDatabaseString(FieldValue),
                                                  FieldID);

            MySqlUtils.ExecuteNonQuery(con, strCommandText);
        }
예제 #2
0
        private void InsertIntoDatabase(MySqlConnection con)
        {
            // Assert(FieldID == 0);
            string strCommandText = string.Format(@"INSERT INTO TargetFormFields VALUES ({0}, {1}, {2}, NULL); SELECT LAST_INSERT_ID() FROM TargetFormFields;",
                                                  TargetID,
                                                  MySqlUtils.RawStringToDatabaseString(FieldName),
                                                  MySqlUtils.RawStringToDatabaseString(FieldValue));

            using (MySqlCommand cmd = new MySqlCommand(strCommandText, con))
            {
                using (MySqlDataReader reader = cmd.ExecuteReader())
                {
                    if (!reader.Read())
                    {
                        throw new Exception(@"Insert: 'SELECT LAST_INSERT_ID()' seems to have failed");
                    }

                    FieldID = reader.GetUInt32(0);
                }
            }
        }