티스토리 뷰
using System;
using System.Data;
using System.Data.SqlClient;
public class DB_TEST
{
public static void Main(string[] args)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString =
"Server=ip;database=CL_ADMIN;uid=sa;pwd=password;";
try
{
conn.Open();
Console.WriteLine("데이터베이스 연결성공..");
String log = " SELECT * FROM dbo.OB_TEST"; // 쿼리문
SqlCommand cmd = new SqlCommand(log, conn); // 적용
SqlDataReader rd = cmd.ExecuteReader(); // 쿼리 수행
while (rd.Read()) //한줄씩 잃기
{
Console.WriteLine(String.Format("{0}, {1}", rd[0],rd[1]));
//내용 출력하는 부분
}
rd.Close();
}
catch
{
Console.WriteLine("데이터베이스 연결 실패..");
}
finally
{
if (conn != null)
{
conn.Close();
}
Console.WriteLine("데이터베이스 연결해제");
}
}
}
출처: http://codezip.tistory.com/181
'응용프로그래밍 > C#' 카테고리의 다른 글
| [C#] int 로 형 변환 (0) | 2011.09.19 |
|---|---|
| DataSet 사용시 연결문자열 노출 안되게 (0) | 2011.09.18 |
| [C#] 텍스트 파일 읽고 쓰기 (0) | 2011.09.15 |
| Debug 창에 나타내려면 (0) | 2010.12.08 |
| [C#] 프로세스와 CPU 사용량 모니터링 및 Kill (0) | 2009.03.05 |
댓글
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- centos
- CSS
- nodejs
- iis
- Debug
- IE
- 안드로이드
- PHP
- 한글
- macos
- ASP
- Linux
- nginx
- laravel
- iphone
- sencha touch
- Mac
- Android
- classic asp
- Docker
- JSON
- API
- JQuery
- Prototype
- javascript
- Wordpress
- IOS
- mssql
- git
- 워드프레스
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
글 보관함