Made a method to execute any sql query from the database, 1) prompt, but the DataTable itself accepts the result of the query from the database (that is, the DataTable does not drag all the data into itself and then does the query on the client side, or the query is base and only the result is given).
class Program { static void Main(string[] args) { string connectionString = @"Data Source=VLADIM\SQLEXPRESS;Initial Catalog=northwind;Integrated Security=True"; string qwery = "SELECT TOP 1000 [ProductID]\r\n ,[ProductName]\r\n FROM [northwind].[dbo].[Current Product List]"; GetZapros2(connectionString,qwery); Console.ReadKey(); } static void GetZapros2(string _connectionString, string qwery) { string connectionString = _connectionString; using (SqlConnection connection = new SqlConnection(connectionString)) if (connection.State != ConnectionState.Open) { connection.Open(); } var dt = new DataTable(); //получаем результат запроса в DataTable... using (var adapter = new System.Data.SqlClient.SqlDataAdapter(qwery, connectionString)) { adapter.Fill(dt); } //далее работаем с DataTable... foreach (DataRow dataRow in dt.Rows) { foreach (var item in dataRow.ItemArray) { Console.WriteLine(item.ToString() + "; "); } Console.WriteLine(); } } } 2) How to effectively catch possible errors. The request for example gave an error, what will I see in the DataTable?