예제 #1
0
 /// <summary>
 /// 执行只返回一行一列的sql语句
 /// </summary>
 /// <param name="sql">sql语句</param>
 /// <param name="parameterBox">参数信息</param>
 /// <returns></returns>
 public object ExecuteScalar(string sql, ParameterBox parameterBox)
 {
     object result = null;
     this.cmd.CommandText = sql;
     foreach (DbParameter param in parameterBox.Parameters)
         this.cmd.Parameters.Add(param);
     result = cmd.ExecuteScalar();
     this.cmd.Parameters.Clear();
     return result;
 }
예제 #2
0
파일: SqlHelper.cs 프로젝트: jyk1987/sdn
 /// <summary>
 /// 执行增删改的预编译sql语句
 /// </summary>
 /// <param name="sql">sql语句</param>
 /// <param name="parameterBox">参数信息</param>
 /// <returns></returns>
 public static int ExecuteNonQuery(string sql, ParameterBox parameterBox)
 {
     int result = -1;
     if (TransactionTransfer.ExistTransaction)
     {
         result = TransactionTransfer.ExecuteSql(sql, parameterBox);
     }
     else
         using (DbCommand cmd = DbHelper.CreateCommand(sql, parameterBox))
         {
             result = cmd.ExecuteNonQuery();
             DbHelper.CloseCommand(cmd);
         }
     return result;
 }
예제 #3
0
파일: SqlHelper.cs 프로젝트: jyk1987/sdn
 /// <summary>
 /// 根据sql语句和参数信息填充DataTable
 /// </summary>
 /// <param name="sql">sql语句</param>
 /// <param name="parameterBox">参数信息</param>
 /// <returns>DataTable</returns>
 public static DataTable GetDataTable(string sql, ParameterBox parameterBox)
 {
     DataTable table = new DataTable();
     DbDataAdapter adapter = DbHelper.CreateDataAdapter(sql, parameterBox);
     adapter.Fill(table);
     DbHelper.CloseDataAdapter(adapter);
     return table;
 }
예제 #4
0
파일: SqlHelper.cs 프로젝트: jyk1987/sdn
 /// <summary>
 /// 根据sql语句和参数信息填充DataSet
 /// </summary>
 /// <param name="sql">sql语句</param>
 /// <param name="parameterBox">参数信息</param>
 /// <returns>DataSet</returns>
 public static DataSet GetDataSet(string sql, ParameterBox parameterBox)
 {
     DataSet ds = new DataSet();
     DbDataAdapter adapter = DbHelper.CreateDataAdapter(sql, parameterBox);
     adapter.Fill(ds);
     DbHelper.CloseDataAdapter(adapter);
     return ds;
 }
예제 #5
0
파일: SqlHelper.cs 프로젝트: jyk1987/sdn
 /// <summary>
 /// 根据sql语句和参数信息产生数据读取器(表结构信息)。
 /// 使用完请调用Close()方法关闭读取器。
 /// </summary>
 /// <param name="sql">sql语句</param>
 /// <param name="pb">参数信息</param>
 /// <returns>参数信息</returns>
 public static DbDataReader GetDataReaderWithInfo(string sql, ParameterBox pb)
 {
     return DbHelper.GetDataReaderWithInfo(sql, pb);
 }
예제 #6
0
파일: SqlHelper.cs 프로젝트: jyk1987/sdn
 /// <summary>
 /// 根据sql语句和参数信息产生数据读取器。
 /// 使用完请调用Close()方法关闭读取器。
 /// </summary>
 /// <param name="sql">sql语句</param>
 /// <param name="parameterBox">参数信息</param>
 /// <returns>数据读取器</returns>
 public static DbDataReader GetDataReader(string sql, ParameterBox parameterBox)
 {
     return DbHelper.CreateDataReader(sql, parameterBox);
 }
예제 #7
0
파일: SqlHelper.cs 프로젝트: jyk1987/sdn
 /// <summary>
 /// 执行返回单结果的sql语句
 /// </summary>
 /// <param name="sql">sql语句</param>
 /// <param name="parameterBox">参数信息</param>
 /// <returns>执行结果</returns>
 public static object ExecuteScalar(string sql, ParameterBox parameterBox)
 {
     object obj = null;
     if (TransactionTransfer.ExistTransaction)
     {
         obj = TransactionTransfer.ExecuteSql(sql, parameterBox);
     }
     else
         using (DbCommand cmd = DbHelper.CreateCommand(sql, parameterBox))
         {
             obj = cmd.ExecuteScalar();
             DbHelper.CloseCommand(cmd);
         }
     return obj;
 }
예제 #8
0
 /// <summary>
 /// 执行带参数的sql语句
 /// </summary>
 /// <param name="sql">sql语句</param>
 /// <param name="parameterBox">参数信息</param>
 public int ExecuteSql(string sql, ParameterBox parameterBox)
 {
     int result = 0;
     this.cmd.CommandText = sql;
     foreach (DbParameter param in parameterBox.Parameters)
         this.cmd.Parameters.Add(param);
     result = this.cmd.ExecuteNonQuery();
     this.cmd.Parameters.Clear();
     return result;
 }