728x90
쿼리문 하나에 parameter 를 변경해 일일히 쿼리하는 일을 아래처럼 하면 dapper 가 알아서 해준다.
#region MultiUpdate
/// <summary>
/// Multipul Update
/// </summary>
private void MultiUpdate()
{
string sql = "UPDATE TestTable SET DATA1 = @DATA1 WHERE ID = @ID;";
using (IDbConnection db = new SqlConnection(this.connectionString))
{
int rowsAffected = db.Execute(sql,
new[]
{
new { ID = 1, DATA1 = "UPDATEA1" },
new { ID = 2, DATA1 = "UPDATEA2" },
}
);
}
}
#endregion
#region MultiDelete
/// <summary>
/// Multipul Delete
/// </summary>
private void MultiDelete()
{
string sql = "DELETE FROM TestTable WHERE ID = @ID;";
using (IDbConnection db = new SqlConnection(this.connectionString))
{
int rowsAffected = db.Execute(sql,
new[]
{
new { Id = 1 },
new { Id = 2 }
}
);
}
}
#endregion
728x90
'C# > Winform' 카테고리의 다른 글
[C#] ILSpay (ICSharpCode) 디컴파일러 (0) | 2022.05.11 |
---|---|
[C#] MessageBox.Show TopMost true 로 띄우기 (0) | 2022.05.10 |
[C#/Dapper] Multi Select (0) | 2022.04.23 |
[C#/Dapper] Bulk Insert (List<T> Insert) (0) | 2022.04.23 |
[C#/Dapper] Dynamic Parameter (0) | 2022.04.23 |