Как выполнить итерацию по нескольким строкам в таблице данных SQL server 2012 ?
Привет,
Я хочу перебрать все строки (всего =11) в таблице данных sqlserver2012.Я получаю только один ряд. Код указан ниже.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.SqlClient; namespace sqlserver_database_ex_cp2 { class Program { static void Main(string[] args) { using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = "Data Source=DESKTOP-F49I231;Initial Catalog=company;Integrated Security=True"; conn.Open(); //create the command SqlCommand command = new SqlCommand("select * from dbo.Employees where EMP_No =@param1", conn); //add the parameters command.Parameters.Add(new SqlParameter("param1", 1)); /* get the rows and display on the screen *This section of the code has the basic code * that will the display the content from the database table. * on the screen using the sqlDataReader */ using (SqlDataReader reader = command.ExecuteReader()) { Console.WriteLine("EMP_NO\tEMP_NAME\tEMP_JOIN_DATE\tEMP_DEPT"); while(reader.Read()) { Console.Write(string.Format("{0}\t| {1} \t | {2} \t | {3}", reader[0], reader[1], reader[2], reader[3])); } } } } } } I want all the rows to be displayed on the console. Please, help me. What I have tried: Whatever I have tried, mentioned in the code.
0x01AA
Выглядит как where EMP_No =@param1
действительно ограничивает результат одной строкой...
Richard MacCutchan
Хороший ответ, но я не могу поддержать комментарий.
0x01AA
Спасибо за повышение мотивации.
hemal p.shah
Каким же тогда должен быть код для более чем одной строки?
0x01AA
См. решение 1
Wendelius
Вы должны опубликовать это как ответ, так как это, скорее всего, причина.