Do so

cmd.CommandText = "тут запрос"; dr = cmd.ExecuteReader(); DataTable schemaTable = new DataTable(); schemaTable.Load(dr);` 

This is done without the first line:

 foreach (DataRow importRow in schemaTable.Rows) { } 

In the request, for example, there are 13 lines, but I see only 12, without the first (exactly without the first, checking by changing the ASC DESC sort), I suspect that the DataTable counts first as a header. In general, the question, sho do?

Even so I checked:

 MessageBox.Show(schemaTable.Rows.Count.ToString()); 

writes 12, and in fact in the query 13 lines.

Screen from Server Manager Studio

  • Imho, somewhere you are mistaken in your code. The documentation for the method Load does not say anything like that. I checked it now in my code - it loads exactly as many lines as it is, without any caps. - Alexander Petrov
  • @AlexanderPetrov code in front of you, where could be the error? foreach can even be ignored. Instead, it is just a MessageBox to understand how many rows are in the request. - Winteriscoming
  • In the sql query. In the real amount of data in the database. - Alexander Petrov
  • @AlexanderPetrov added a screen from the studio manager the result of this query. - Winteriscoming
  • Good. And if you make a request cmd.CommandText = "select 1 a union select 2" line one? - nick_n_a

1 answer 1

I won by typing, I do not know why it works like that. I did and everything is ok.

 cmd.CommandText = "тут запрос"; dr = cmd.ExecuteReader(); DataTable schemaTable = new DataTable(); schemaTable.Load(dr); 

Instead of this

 schemaTable.Load(dr); 

Did so

 schemaTable.Load(cmd.ExecuteReader());