close

Trust Me!! Trust You!!


  • Blog
  • Local Log
  • Tag Cloud
  • Key Log
  • Guestbook
  • RSS Feed
  • Write a Post
  • Admin

혹시 블로그 스킨이 깨져 보이시나요? 최신버전의 Internet Explorer(Windows용), Opera, Firefox를 사용해보세요.

C# DB helper > DBHelper.cs

App 프로그래밍
2016/03/01 23:37
 
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using System.Data.SqlClient; using System.Collections.Generic; using System.Collections.Specialized; namespace Helpers { public static class DBHelper { #if DEBUG private static string defaultConnectionString = "Data Source=localhost;Initial Catalog=GLOBOBH_MapaAntenas;Integrated Security=SSPI"; #else private static string defaultConnectionString = ""; #endif public static string DefaultConnectionString { get { return defaultConnectionString; } } public static DataTable ExecuteProcedure(string PROC_NAME, params object[] parameters) { try { if (parameters.Length % 2 != 0) throw new ArgumentException("Wrong number of parameters sent to procedure. Expected an even number."); DataTable a = new DataTable(); List filters = new List(); string query = "EXEC " + PROC_NAME; bool first = true; for (int i = 0; i < parameters.Length; i += 2) { filters.Add(new SqlParameter(parameters[i] as string, parameters[i + 1])); query += (first ? " " : ", ") + ((string)parameters[i]); first = false; } a = Query(query, filters); return a; } catch (Exception ex) { throw ex; } } public static DataTable ExecuteQuery(string query, params object[] parameters) { try { if (parameters.Length % 2 != 0) throw new ArgumentException("Wrong number of parameters sent to procedure. Expected an even number."); DataTable a = new DataTable(); List filters = new List(); for (int i = 0; i < parameters.Length; i += 2) filters.Add(new SqlParameter(parameters[i] as string, parameters[i + 1])); a = Query(query, filters); return a; } catch (Exception ex) { throw ex; } } public static int ExecuteNonQuery(string query, params object[] parameters) { try { if (parameters.Length % 2 != 0) throw new ArgumentException("Wrong number of parameters sent to procedure. Expected an even number."); List filters = new List(); for (int i = 0; i < parameters.Length; i += 2) filters.Add(new SqlParameter(parameters[i] as string, parameters[i + 1])); return NonQuery(query, filters); } catch (Exception ex) { throw ex; } } public static object ExecuteScalar(string query, params object[] parameters) { try { if (parameters.Length % 2 != 0) throw new ArgumentException("Wrong number of parameters sent to query. Expected an even number."); List filters = new List(); for (int i = 0; i < parameters.Length; i += 2) filters.Add(new SqlParameter(parameters[i] as string, parameters[i + 1])); return Scalar(query, filters); } catch (Exception ex) { throw ex; } } #region Private Methods private static DataTable Query(String consulta, IList parametros) { try { DataTable dt = new DataTable(); SqlConnection connection = new SqlConnection(defaultConnectionString); SqlCommand command = new SqlCommand(); SqlDataAdapter da; try { command.Connection = connection; command.CommandText = consulta; if (parametros != null) { command.Parameters.AddRange(parametros.ToArray()); } da = new SqlDataAdapter(command); da.Fill(dt); } finally { if (connection != null) connection.Close(); } return dt; } catch (Exception) { throw; } } private static int NonQuery(string query, IList parametros) { try { DataSet dt = new DataSet(); SqlConnection connection = new SqlConnection(defaultConnectionString); SqlCommand command = new SqlCommand(); try { connection.Open(); command.Connection = connection; command.CommandText = query; command.Parameters.AddRange(parametros.ToArray()); return command.ExecuteNonQuery(); } finally { if (connection != null) connection.Close(); } } catch (Exception ex) { throw ex; } } private static object Scalar(string query, List parametros) { try { DataSet dt = new DataSet(); SqlConnection connection = new SqlConnection(defaultConnectionString); SqlCommand command = new SqlCommand(); try { connection.Open(); command.Connection = connection; command.CommandText = query; command.Parameters.AddRange(parametros.ToArray()); return command.ExecuteScalar(); } finally { if (connection != null) connection.Close(); } } catch (Exception ex) { throw ex; } } #endregion } }
이올린에 북마크하기
No received trackback. / No comment.

Trackback Address :: http://viper150.cafe24.com/trackback/275

You can also say.

Prev 1 ... 25 26 27 28 29 30 31 32 33 ... 298 Next
블로그 이미지
이것저것 불펌금지도 퍼다가 담습니다. 외부에 비공개된 페이지 입니다. By. 어른왕자

카테고리

  • 전체 (298)
    • 사는 이야기 (115)
    • 웹 프로그래밍 (102)
    • App 프로그래밍 (22)
    • IT 뉴스&기타 (22)
    • 박한별 (4)
    • 역사&기타지식 (9)

태그목록

  • 6.25
  • 붕당정치
  • BHO
  • 울트라에디터
  • c substring
  • Menu
  • 계산
  • 국가통계포털
  • 화형
  • 수면부족
  • api 한글화
  • 남편
  • 우리
  • 김용환
  • 이클립스 루트
  • 조선
  • 그래픽카드
  • 해킹흔적검색
  • 수출
  • 메뉴바
  • 박근혜
  • 텔레비젼
  • java.util.List
  • 조폭영화
  • 마우스
  • 만화
  • getdate
  • tab
  • Button
  • 수원

최근에 올라온 글

  • 보험사의 조정신청 대응방법.
  • 어느 천재의 앞선 시선.
  • [병맛더빙] 누구게..... (1)
  • 韓경제 `회색 코뿔소` 상황...
  • SVN Connector 설치 URL.
  • 군대를 가지 않는 서울대생.
  • “운은 하늘의 귀여움 받는...
  • 목장에서 알바하다가 캐스...
  • [펌]믿고 거르는 관상.
  • 하루에 1세트씩 하면 좋다...

최근에 달린 댓글

  • <p><img src="https://i.imgur... 브레드 01/22
  • <p><img src="https://i.imgur... 브레드 01/22
  • <p><img src="https://i.imgur... 브레드 01/22
  • <p><img src="https://i.imgur... 브레드 01/22
  • <p><img src="https://i.imgur... 브레드 01/22

최근에 받은 트랙백

  • công ty may đồng phục. công ty may đồng phục 01/08
  • Israelnightclub`s recent blo... Israelnightclub`s recent blo.. 01/06
  • Suggested Browsing. Suggested Browsing 01/06
  • similar site. similar site 01/06
  • לאתר הבית שלנו. לאתר הבית שלנו 01/06

글 보관함

  • 2019/03 (1)
  • 2018/12 (1)
  • 2018/09 (1)
  • 2018/08 (1)
  • 2018/02 (1)

달력

«   2021/01   »
일 월 화 수 목 금 토
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            

링크

  • Total : 262034
  • Today : 21
  • Yesterday : 46
Tattertools
Eolin
rss

어른왕자's blog is powered byTattertools1.1.2.2 : Animato