U
U
User992018-04-11 14:49:24
ASP.NET
User99, 2018-04-11 14:49:24

How to make a cyclic query to the database?

I can’t make a cyclic query to the database, for example, in Delphi you can do this

var i:int;
......
TQuery1.first;
for i:=0 to Tquery1.RecordCount -1 do // то есть выполняется запрос пока не кончится все записи в таблице
begin
TQuery2.Close;
TQuery2.SQL.Text:='SELECT * FROM tablica WHERE PREDMET='''+TQuery1PREDMET.Value+'''';
Tquery2.ExecSQL;
Tquery1.Next;
end;

Table TQuery2 executes a query against another table for all records in table TQuery1, column PREDMET. How can this be done in asp.net? or is there another option? In general, there is such a task
There is a table with the names of items Predmets, and there is a table with estimates, dates Balls. the Balls table is linked to Predmets one-to-many (PredmetId). I need to put it out like this5acdf4bbeef89574470072.jpeg

Items alone are normally displayed as they should. Now I can’t display all items in one list in one views

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
eRKa, 2018-04-12
@User99

Small notes:
1. Before copying the code here, it is better to copy-paste it into a notepad, format it there (delete extra tabs on the left), and then only copy-paste it from the notepad here. It is hard to accept badly formatted code, especially when there is a lot of it.
2. It is very difficult to read code with incomprehensible names. It is better to stick to the tradition of naming in normal English. Fix the page with Google translator in the browser and, if necessary, translate into English - a matter of a couple of seconds. No abbreviations, fields in the models - only the first letter is capitalized. Some of the names I did not understand what you designated them.
3. The teacher of the subject is a user, which means that it is necessary to bind not by his name, but by his Id. Instead of
it is better
4. Then I try to figure out what and how you want to find
What is GR I did not understand. You might think that the entity is a group, but it is a string. Group name? Is each item tied to a specific group?
My choice is how it should be
where Group is an entity that is related to lesson as one-to-many. Sample Model

public class Group
{
  public int Id { get; set; }
  public string Name { get; set; }    // название группы
  public ICollection<Lesson> Lessons { get; set; }    // предметы
  public ICollection<Learner> Learners { get; set; }  // ученики
}

What are contingents? Students? Then my version would look like this
I couldn't even intuitively guess what Jjours is. Judging by the model, this is an entity that stores the rating, the date when it was set, etc. But you called the result jocenki, and there will be no ratings there. There will be items in which data about Jjours will immediately be pulled up. And you again find the item that you already found when you were looking for the group. It could be done like this
var lesson = db.Lessons.Find(l => l.Id == id).Include(t => t.Jjours);
var group = lesson.Group;

Further, I assume that it should be like this
var jour = new Journalsliv();
jour.Learners = learners;
jour.Jjoursliv= group.Jjours;

This could be simplified by doing this
var group = db.Lessons.Find(l => l.Id == id).Include(t => t.Jjours).Group;
var jour = new Journalsliv
{
  Learners = db.Learners.Where(k => k.GroupId == group.Id).ToList(),
  Jjoursliv = group.Jjours.OrderBy(j => j.Date).ToList()  // на всякий случай сортируем по дате
}

5. Well, according to the output on the client. I don't know how it is in your task, but to display dates in width, it will be cruel if they need to be displayed for a sufficiently long period. In general, dates can be infinite, and the number of students is always limited. I would do the opposite: students are fields (width) and dates are records (length).
Well, the main mistake you have in this code
@foreach (var roc in Model.Jjoursliv)
{
    <tr>
        <td>@roc.IIN</td>
        @foreach (var roc2 in Model.Jjoursliv)
        {
            <td>@roc2.OCENKA</td>
        }
    </tr>
}

I don’t understand the logic of storing grades at all, since you are trying to get them in this way. Judging by your code, Jjoursliv is a collection of Jjour, and Jjour is one grade for one student. And with the code above, you display the grades of other students for each student, i.e. for each you will display the same sequence of assessments of other students, so they look the same for you.
You need to first group all grades by name.
This will give you a collection of students that will consist of a collection of grades.
And then it can be output like this
@foreach (var learner in learners)
{
    <tr>
        <td>@learner.First().IIN</td>
        @foreach (var jour in learner)
        {
            <td>@jour.OCENKA</td>
        }
    </tr>
}

In summary, I would like to recommend: take a closer look at what Include does and how ToList() works and in what cases it is needed; to revise the database structure, there are errors, so there were difficulties with understanding how to make a selection.

S
Sergey Lerg, 2014-03-09
@wapmorgan

MIT if you don't care how the program is used.
www.freebsdnews.net/wp-content/uploads/open-source...

O
OnYourLips, 2014-03-09
@OnYourLips

wtfpl.org

I
Ivan Kupalov, 2014-03-09
@charlag_khan

choosealicense.com

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question