Ejemplo n.º 1
0
        //Insert data into DB
        public bool Insert(WordClass c)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(myconnstring);

            try {
                string     sql = "INSERT INTO WT_table (Word, Translate) VALUES (@Word, @Translate)";
                SqlCommand cmd = new SqlCommand(sql, conn);
                if (String.IsNullOrEmpty(Word))
                {
                    cmd.Parameters.AddWithValue("@Word", DBNull.Value);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@Word", c.Word);
                }
                if (String.IsNullOrEmpty(Translate))
                {
                    cmd.Parameters.AddWithValue("@Translate", DBNull.Value);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@Translate", c.Translate);
                }
                if (cmd.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("Inserted");
                }
                conn.Open();
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
                throw;
            }
            finally {
                conn.Close();
            }

            return(isSuccess);
        }
Ejemplo n.º 2
0
        //Delete data from DB
        public bool Delete(WordClass c)
        {
            bool          isSucccess = false;
            SqlConnection conn       = new SqlConnection(myconnstring);

            try {
                string     sql = "DELETE FROM WT_table WHERE WordID=@WordID";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@WordID", c.WordID);
                conn.Open();
                if (cmd.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("Inserted");
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
                throw;
            }
            finally {
                conn.Close();
            }
            return(isSucccess);
        }