Database based query listing

Asked

Viewed 105 times

0

First of all, I apologise if the question is vague, as it is a very broad subject.

Today I have a student registration and consultation system, where the query is made exclusively by CPF, since it is a unique identifier and a Constraint in the database will assure me that there will be no repeated CPF, thus returning only one result in the query.

The query in the database is done via dataset, by an Auxiliadora class that we have. The method is basically this:

CeltaWare.Data.SqlHelper.FillDataset(
                    sqlConn,
                    CommandType.Text,
                    "SELECT * FROM ALUNOS WHERE CPF = @CPF",
                    dataSet,
                    new string[] { "Alunos" },
                    new SqlParameter("@CPF", aluno.Cpf));

And if in the case, I want to search by name too?

Obviously, there may be several students with the same first name, and then the app should return a list to select the student we want.

The question is: How should this list be created? Being a beginner in C#, I don’t have much idea how to do this. It would be a new Form, with Abels who would have the Text replaced by our research?

Thank you in advance!

  • You didn’t report which one is yours front end, if Forms or Web, but how can it be more of a record, a kind grid can help (Gridview for example)

  • Sorry, it’s Windowsforms

  • In that case you can use Datagridview, all documentation with examples you can see here: https://docs.microsoft.com/pt-br/dotnet/framework/winforms/controls/datagridview-control-overview-windows-forms

  • @Lucasbustos the Datagridview would be the ideal opposition, more if you prefer to use a List<Aluno>: You have to create a Student Class list by feeding your properties with a foreach going through all the columns of each row of your dataset. Put the Class Aluno and the entire method used in the dataset to serve as the basis, which assembles a scheme from the dataset you already have.

1 answer

1

In my system, we do this, with difference in language only.

  • We perform the consultation always via name. -- We treat so that if the return of the query is greater than 1, present the data on a screen ("List People") -- Where we place the Code, CPF and Person Name. --- Then when you double-click Person, load the data into the register.

-- The Canvas is composed by a List.

I don’t know if it’s clear, but it follows the same principle of the solution you imagined.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.