Ejemplo n.º 1
0
 /// <summary>
 /// 查询
 /// </summary>
 /// <returns></returns>
 public DataTable Select(SqlCommand cmd)
 {
     if (cmd == null)
     {
         throw new ArgumentNullException("cmd");
     }
     cmd.Connection = DBConnection.Current;
     lock (cmd.Connection)
     {
         try
         {
             if (cmd.Connection.State != ConnectionState.Open)
             {
                 cmd.Connection.Open();
             }
             using (SqlDataAdapter da = new SqlDataAdapter(cmd))
             {
                 DataTable dt = new DataTable();
                 da.Fill(dt);
                 return(dt);
             }
         }
         catch (SqlException e)
         {
             if (!SDLHelper.Failback(e)) // 在MSSQL建立链接时出现网路相关问题
             {
                 throw e;
             }
             return(this.Select(cmd));
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 查询
 /// </summary>
 /// <param name="procedure">存储过程</param>
 /// <param name="value">参数</param>
 /// <returns></returns>
 public DataTable Select(string procedure, object value)
 {
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     return(this.Select(procedure, SDLHelper.GetParameters(value)));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="cmd">命名行</param>
 /// <returns></returns>
 public int UpdateReturnInt(SqlCommand cmd)
 {
     if (cmd == null)
     {
         throw new ArgumentNullException("cmd");
     }
     cmd.Transaction = this.Transaction;
     return(SDLHelper.ExecuteNonQuery(cmd, this.Connection));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <returns></returns>
 public bool Delete(SqlCommand cmd)
 {
     if (cmd == null)
     {
         throw new ArgumentNullException("cmd");
     }
     cmd.Transaction = this.Transaction;
     //
     return(SDLHelper.ExecuteNonQuery(cmd, this.Connection) > 0);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 插入一行
 /// </summary>
 /// <returns></returns>
 public bool Insert(object value, string table)
 {
     if (value == null || string.IsNullOrEmpty(table))
     {
         throw new ArgumentException();
     }
     using (SqlCommand cmd = SDLHelper.CreateInsert(value, table))
     {
         return(this.Insert(cmd));
     }
 }
Ejemplo n.º 6
0
 /// <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 (SqlCommand cmd = SDLHelper.CreateUpdate(value, table, key, where))
     {
         return(this.Update(cmd));
     }
 }
Ejemplo n.º 7
0
 /// <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(SDLHelper.GetParameters(value), procedure));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 插入一行
 /// </summary>
 /// <returns></returns>
 public object InsertScalar(SqlCommand cmd, params SqlParameter[] parameters)
 {
     if (cmd == null)
     {
         throw new ArgumentNullException("cmd");
     }
     if (parameters != null)
     {
         cmd.Parameters.AddRange(parameters);
     }
     cmd.Transaction = this.Transaction;
     return(SDLHelper.ExecuteScalar(cmd, this.Connection));
 }