728x90
1. Nuget 에서 Dapper 설치
2. 기본 사용
public class TestDataModel
{
public int ID { get; set; }
public string DATA1 { get; set; }
public string DATA2 { get; set; }
public string DATA3 { get; set; }
}
using Dapper;
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Windows;
using System.Windows.Input;
private string connectionString = "Server=192.168.0.20;Database=kjundb;User Id=userid;Password=1234;";
using (IDbConnection db = new SqlConnection(this.connectionString))
{
db.Open();
// ■ Scalar
var eventTime = db.Query<DateTime>("SELECT EventTime FROM TestTable WHERE ID = 1").SingleOrDefault();
// ■ Basic Query
var parameters = new { id = 18 };
string sql = "SELECT * FROM TestTable WHERE ID = @id";
var result = db.Query<TestDataModel>(sql, parameters);
}
728x90
'C# > Winform' 카테고리의 다른 글
[C#/Dapper] Dynamic Parameter (0) | 2022.04.23 |
---|---|
[C#/Dapper] Dynamic Result (0) | 2022.04.23 |
[C#] VB → C# (0) | 2022.04.22 |
[C#] Point 들간 거리 순으로 정렬하기 / Point List Sort (0) | 2022.04.22 |
[C#] BinaryWriter, BinaryReader 사용하기 (0) | 2022.04.01 |