C# mssql 접속 및 Select 예제
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
C# program that uses SqlConnection
using System;
using System.Data.SqlClient;
class Program
{
static void Main()
{
//
// First access the connection string.
// ... This may be autogenerated in Visual Studio.
//
string connectionString =
ConsoleApplication1.Properties.Settings.Default.ConnectionString;
//
// In a using statement, acquire the SqlConnection as a resource.
//
using (SqlConnection con = new SqlConnection(connectionString))
{
//
// Open the SqlConnection.
//
con.Open();
//
// The following code uses an SqlCommand based on the SqlConnection.
//
using (SqlCommand command = new SqlCommand("SELECT TOP 2 * FROM Dogs1", con))
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine("{0} {1} {2}",
reader.GetInt32(0), reader.GetString(1), reader.GetString(2));
}
}
}
}
}'Language > C#' 카테고리의 다른 글
| File Write 시에 모니터링 및 끝나면 다음 동작 수행 (6) | 2015.11.11 |
|---|---|
| 텍스트 파일을 한 번에 한 줄씩 읽기 (6) | 2015.09.25 |
| string 을 공백문자를 구별자로 split 하고 싶을때 (4) | 2015.09.15 |
| Listview 복사(복제하기) (4) | 2015.09.11 |
| MessageBox 옵션... Error 메시지 띄울때 (6) | 2015.08.31 |