예제 #1
0
 /// <summary>
 /// 返回DataTable
 /// </summary>
 /// <param name="str"></param>
 /// <returns></returns>
 public DataTable GetDataTable(string sql)
 {
     try
     {
         SqlConnection  con = new SqlConnection(connStr);
         SqlDataAdapter adp = new SqlDataAdapter(sql, con);
         DataSet        ds  = new DataSet();
         adp.Fill(ds);
         return(ds.Tables[0]);
     }
     catch (Exception ex)
     {
         DalLogger.WriteErrorLog(ex);
         throw ex;
     }
 }
예제 #2
0
 /// <summary>
 /// 返回第一行第一列
 /// </summary>
 /// <param name="str"></param>
 /// <returns></returns>
 public object ExecuteScalar(string sql)
 {
     try
     {
         object obj = null;
         using (SqlConnection con = new SqlConnection(connStr))
         {
             con.Open();
             SqlCommand cmd = new SqlCommand(sql, con);
             obj = cmd.ExecuteScalar();
         }
         return(obj);
     }
     catch (Exception ex)
     {
         DalLogger.WriteErrorLog(ex);
         throw ex;
     }
 }
예제 #3
0
 /// <summary>
 /// 增删改、返回影响行数
 /// </summary>
 /// <param name="str"></param>
 /// <returns></returns>
 public int ExecuteNonQuery(string sql)
 {
     try
     {
         int i = 0;
         using (SqlConnection con = new SqlConnection(connStr))
         {
             con.Open();
             SqlCommand cmd = new SqlCommand(sql, con);
             i = cmd.ExecuteNonQuery();
         }
         return(i);
     }
     catch (Exception ex)
     {
         DalLogger.WriteErrorLog(ex);
         throw ex;
     }
 }
예제 #4
0
 public DataTable GetDataTable(string sql)
 {
     using (SqlConnection conn = new SqlConnection(connStr))
     {
         SqlCommand cmd = new SqlCommand(sql, conn);
         try
         {
             SqlDataAdapter adp = new SqlDataAdapter(cmd);
             DataSet        ds  = new DataSet();
             adp.Fill(ds);
             DataTable dt = ds.Tables[0];
             return(dt);
         }
         catch (Exception ex)
         {
             DalLogger.WriteErrorLog(ex);
             throw ex;
         }
         finally
         { conn.Close(); }
     }
 }
예제 #5
0
 public DataTable GetDataTable(string sql)
 {
     using (OleDbConnection conn = new OleDbConnection(strConn))
     {
         OleDbCommand cmd = new OleDbCommand(sql, conn);
         try
         {
             conn.Open();
             OleDbDataAdapter adp = new OleDbDataAdapter(cmd);
             DataSet          ds  = new DataSet();
             adp.Fill(ds);
             conn.Close();
             DataTable dt = ds.Tables[0];
             return(dt);
         }
         catch (Exception ex)
         {
             DalLogger.WriteErrorLog(ex);
             throw ex;
         }
     }
 }