forked from AlexanderLea/csharp-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuestion2.cs
35 lines (28 loc) · 1.02 KB
/
Question2.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using Example.Interview.Question.Placeholders;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace csharp_interview
{
public class Question2
{
string connectionString = "Data Source=(local);Initial Catalog=Northwind;Integrated Security=true";
public DataTable ReadPersonData(string jobTitle)
{
SqlConnection connection = new SqlConnection(connectionString);
var command = new SqlCommand($"SELECT ItemId, FirstName, LastName FROM People WHERE JobTitle = '{jobTitle}' ORDER BY Age DESC;", connection);
connection.Open();
var result = new DataTable();
var dataAdapter = new SqlDataAdapter(command);
result.BeginLoadData();
dataAdapter.Fill(result);
result.EndLoadData();
return result;
}
}
}