Good day. There is a table in the database, there are 4 columns in the table: Name, Date, Code, INN. I need to output using SQL query Name, Date, Code to the console. How to display three column values at once select Name, Date, Code from tRefuseTable where inn = '{0}'? I tried to display only Name
string ConString = "connstring;"; using (SqlConnection connection = new SqlConnection(ConString)) { using (SqlCommand command = connection.CreateCommand()) { command.CommandText = string.Format(@"select Name from tRefuseTable where inn='{0}'", item.INN_Legal);//текст запроса connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Console.WriteLine(reader[0].ToString() ) ;//вывод результата на консоль } } }
reader[0],reader[1],reader[2](and betterreader["Name"], etc.) - Andrey NOPGetXXX(...)method instead of the indexer, for examplereader.GetString(0)- Andrey NOP