Exemplo n.º 1
0
 /// <summary>
 /// 查询
 /// </summary>
 /// <returns></returns>
 public DataTable Select(MySqlCommand cmd)
 {
     if (cmd == null)
     {
         throw new ArgumentNullException("cmd");
     }
     cmd.Connection = MysqlDBConnection.Current;
     lock (cmd.Connection)
     {
         try
         {
             if (cmd.Connection.State != ConnectionState.Open)
             {
                 cmd.Connection.Open();
             }
             using (MySqlDataAdapter da = new MySqlDataAdapter(cmd))
             {
                 DataTable dt = new DataTable();
                 da.Fill(dt);
                 return(dt);
             }
         }
         catch (MySqlException e)
         {
             if (!MysqlSDLHelper.Failback(e)) // 在MSSQL建立链接时出现网路相关问题
             {
                 throw e;
             }
             return(this.Select(cmd));
         }
     }
 }
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="cmd">命名行</param>
 /// <returns></returns>
 public int UpdateReturnInt(MySqlCommand cmd)
 {
     if (cmd == null)
     {
         throw new ArgumentNullException("cmd");
     }
     cmd.Transaction = this.Transaction;
     return(MysqlSDLHelper.ExecuteNonQuery(cmd, this.Connection));
 }
 /// <summary>
 /// 删除
 /// </summary>
 /// <returns></returns>
 public bool Delete(MySqlCommand cmd)
 {
     if (cmd == null)
     {
         throw new ArgumentNullException("cmd");
     }
     cmd.Transaction = this.Transaction;
     //
     return(MysqlSDLHelper.ExecuteNonQuery(cmd, this.Connection) > 0);
 }
 /// <summary>
 /// 插入一行
 /// </summary>
 /// <returns></returns>
 public bool Insert(object value, string table)
 {
     if (value == null || string.IsNullOrEmpty(table))
     {
         throw new ArgumentException();
     }
     using (MySqlCommand cmd = MysqlSDLHelper.CreateInsert(value, table))
     {
         return(this.Insert(cmd));
     }
 }
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="value">映射的对象</param>
 /// <param name="table">表</param>
 /// <param name="key">主键</param>
 /// <param name="where">条件</param>
 /// <returns></returns>
 public bool Update(object value, string table, string key, string where)
 {
     if (value == null || string.IsNullOrEmpty(table) || string.IsNullOrEmpty(key))
     {
         throw new ArgumentException();
     }
     using (MySqlCommand cmd = MysqlSDLHelper.CreateUpdate(value, table, key, where))
     {
         return(this.Update(cmd));
     }
 }
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="procedure">存储过程</param>
 /// <param name="value">参数</param>
 /// <returns></returns>
 public bool Update(string procedure, object value)
 {
     if (string.IsNullOrEmpty(procedure))
     {
         throw new ArgumentException("procedure");
     }
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     return(this.Update(MysqlSDLHelper.GetParameters(value), procedure));
 }
 /// <summary>
 /// 插入一行
 /// </summary>
 /// <returns></returns>
 public object InsertScalar(MySqlCommand cmd, params MySqlParameter[] parameters)
 {
     if (cmd == null)
     {
         throw new ArgumentNullException("cmd");
     }
     if (parameters != null)
     {
         cmd.Parameters.AddRange(parameters);
     }
     cmd.Transaction = this.Transaction;
     return(MysqlSDLHelper.ExecuteScalar(cmd, this.Connection));
 }