Example #1
0
 /// <summary>
 /// 填充
 /// </summary>
 /// <param name="com"></param>
 /// <param name="array"></param>
 void SetParametersArray(ref OleDbCommand com, ParametersArray array)
 {
     foreach (OleDbParameter item in array.GetArray())
     {
         com.Parameters.Add(item);
     }
 }
Example #2
0
 /// <summary>
 /// 读取查询结果中的第一行第一列
 /// </summary>
 /// <param name="sql"></param>
 /// <returns></returns>
 public object ExecuteScalar(string sql, ParametersArray array)
 {
     try
     {
         OleDbCommand com = new OleDbCommand(sql, con);
         SetParametersArray(ref com, array);
         return(com.ExecuteScalar());
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #3
0
 public OleDbDataReader ExecuteReader(string sql, ParametersArray array)
 {
     try
     {
         OleDbCommand com = new OleDbCommand(sql, con);
         SetParametersArray(ref com, array);
         OleDbDataReader reader = com.ExecuteReader();
         return(reader);
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #4
0
 /// <summary>
 /// 返回DataSet
 /// </summary>
 /// <param name="sql"></param>
 /// <returns></returns>
 public DataSet GetDataSet(string sql, ParametersArray array)
 {
     try
     {
         OleDbCommand com = new OleDbCommand(sql, con);
         SetParametersArray(ref com, array);
         using (OleDbDataAdapter adpter = new OleDbDataAdapter(com))
         {
             DataSet ds = new DataSet();
             adpter.Fill(ds);
             return(ds);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #5
0
 /// <summary>
 /// 执行Insert语句,并返回新添加的记录ID
 /// </summary>
 /// <param name="sql"></param>
 /// <param name="array"></param>
 /// <returns></returns>
 public object ExecuteNonQueryAndGetIdentity(string sql, ParametersArray array)
 {
     try
     {
         OleDbCommand com = new OleDbCommand(sql, con);
         SetParametersArray(ref com, array);
         if (com.ExecuteNonQuery() >= 1)
         {
             com.CommandText = "select @@identity";
             return(com.ExecuteScalar());
         }
         else
         {
             throw new Exception("记录添加不成功!");
         }
     }
     catch (Exception)
     {
         throw;
     }
 }