/// <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); } }
/// <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; } }
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; } }
/// <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; } }
/// <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; } }