Getting Started - W3Schools - SqlConnection

CSharp · Console

/Program.cs

// @nuget: Dapper -Version 1.60.6
using Dapper;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
					
public class Program
{	
	public class Customer 
	{
		public int CustomerID {get;set;}
		public string CustomerName {get;set;}
		public string ContactName {get;set;}
		public string Address {get;set;}
		public string City {get;set;}
		public string PostalCode {get;set;}
		public string Country {get;set;}
	}
	
	public static void Main()
	{		
		using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServerW3Schools()))
		{
			connection.Execute("INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country) VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');");
		}	
		
		
		using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServerW3Schools()))
		{
			var customer = connection.Query<Customer>("Select * FROM CUSTOMERS Where CustomerName ='Cardinal'").ToList();
			
			Console.WriteLine("Row Insert : " + customer.Count());
			
			FiddleHelper.WriteTable(connection.Query<Customer>("Select TOP 10 * FROM CUSTOMERS Where CustomerName like 'C%'").ToList());
		}	
	}
}
;