Beispiel #1
0
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="pkName">字段主键</param>
        /// <param name="pkVal">字段值</param>
        /// <returns></returns>
        public static int DeleteData(string connectionString, string tableName, string pkName, string pkVal)
        {
            StringBuilder sb = new StringBuilder("Delete From " + tableName + " Where " + pkName + " = ?ID");

            return(MySqlHelper.ExecuteNonQuery(connectionString, CommandType.Text, sb.ToString(), new MySqlParameter[] { new MySqlParameter("?ID", pkVal) }));
        }
Beispiel #2
0
        /// <summary>
        /// 通过Dictionary插入数据
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="ht">Hashtable</param>
        /// <returns>int</returns>
        public static int InsertByHashtable(string connectionString, string tableName, Dictionary <string, string> ht)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(" Insert Into ");
            sb.Append(tableName);
            sb.Append("(");
            StringBuilder sp       = new StringBuilder();
            StringBuilder sb_prame = new StringBuilder();

            foreach (string key in ht.Keys)
            {
                sb_prame.Append("," + key);
                sp.Append(",?" + key);
            }
            sb.Append(sb_prame.ToString().Substring(1, sb_prame.ToString().Length - 1) + ") Values (");
            sb.Append(sp.ToString().Substring(1, sp.ToString().Length - 1) + ")");
            int _object = MySqlHelper.ExecuteNonQuery(connectionString, CommandType.Text, sb.ToString(), MySqlHelper.GetParameter(ht));

            return(_object);
        }