Answer the question
In order to leave comments, you need to log in
How to work with the database in c# and other programming languages?
Hello. I am new to programming languages such as C#, C, C++, Java and others.
Here I am learning C#. There was a question, and whether correctly I work with a DB? I read 3 books about this, but everyone advises differently and I don’t know if I’m doing the right thing.
At the moment there is a login form for the program. There are three functions in total:
The first one starts working when the program is opened. It opens the connection and displays accounts from which you can choose your own. The connection is closed.
The second one works when the user has entered a password and tries to log in. The connection opens and we check the password.
The third one is for connection testing. The connection also opens and closes.
In fact, all functions are something like this:
private void SQLFunction(){
sqlConnection = new SqlConnection("Server=" + Properties.Settings.Default.SQLServer + ";Database=" + Properties.Settings.Default.SQLDateBase + ";User ID=" + Properties.Settings.Default.SQLLogin + ";Password=" + Properties.Settings.Default.SQLPass + ";");
try {
sqlConnection.Open(); SqlCommand command = new SqlCommand("SELECT id, name, surname, patronymic FROM staff WHERE type = '1'", sqlConnection); ТУТ ЧИТАЕМ ПОЛУЧЕННОЕ.
}
catch{
ТУТ ОШИБКА ЕСЛИ ПОДКЛЮЧЕНИЕ НЕ УДАЛОСЬ.
}
sqlConnection.Close(); // Закрываем соединение.
}
Answer the question
In order to leave comments, you need to log in
https://github.com/aura-project/melia
C# example of working with the database and in general
See what kind of software.
desktop for the end user should not use the database at all (unless local)
if the server is the example above
Correct, at least if there is no high load, on Web sites it is the same, the protocol with the client is sessional, and with each request it is reopened/closed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question