Created
July 19, 2020 14:03
-
-
Save mikependon/67f695b4cfbc0d027062c662cb1d613b to your computer and use it in GitHub Desktop.
ADO_Query.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (var connection = new SqlConnection(connectionString)) | |
{ | |
connection.Open(); | |
using (var command = connection.CreateCommand()) | |
{ | |
command.CommandText = "SELECT Id, Name, ... FROM [dbo].[Customer];"; | |
var list = new List<Customer>(); | |
using (reader = command.ExecuteReader()) | |
{ | |
var customer = new Customer | |
{ | |
Id = reader.GetInt32(0), | |
Name = reader.GetString(1), | |
... | |
}; | |
list.Add(customer); | |
} | |
return customer; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment