A
A
Andrey Fomin2021-06-07 17:24:49
SQL
Andrey Fomin, 2021-06-07 17:24:49

How to correct errors?

Hello!
Here are my few mistakes:
1. Syntax error in sql query, but I don't see what's wrong

sqlUpdate =
                @"UPDATE Автомобиль SET WHERE VIN_номер = @VIN AND Номер_заказа = @Заказ AND Номер_филиала = @Филиал";

60be2a115edca169796662.png
2. This code deletes a record from the database, and it seems like the variable is declared, so what's the problem?
string sqlDelete = "";
                int zakaz = Convert.ToInt32(Nomer_zakaza.Text);
                int filial = Convert.ToInt32(Nomer_filiala.Text);
                sqlDelete =
                @"DELETE FROM Автомобиль WHERE VIN_номер = @VIN AND Номер_заказа = @Заказ AND Номер_филиала = @Филиал";
                SqlConnection connection = new SqlConnection("Data Source = LAPTOP-KJLU9H2F\\SQLEXPRESS; Initial Catalog = 'Автосалон'; Integrated Security = True");
                connection.Open();
                SqlCommand command = connection.CreateCommand();
                command.CommandText = sqlDelete;
                command.Parameters.Add("@VIN", SqlDbType.VarChar, 20).Value = VIN.Text;
                command.Parameters.Add("@Заказ", SqlDbType.Int).Value = zakaz;
                command.Parameters.Add("@Филиал", SqlDbType.Int).Value = filial;
                SqlCommand cmd = new SqlCommand(sqlDelete, connection);
                cmd.ExecuteNonQuery();

60be2a3d96f60399444323.png
3. This code adds a record from the database, and a variable is declared here too, so what's the problem?
string sqlInsert = "";
                int zakaz = Convert.ToInt32(Nomer_zakaza.Text);
                int filial = Convert.ToInt32(Nomer_filiala.Text);
                sqlInsert =
                @"INSERT INTO Автомобиль (VIN_номер, Номер_заказа, Номер_филиала) VALUES (@VIN,@Заказ,@Филиал)";
                SqlConnection connection = new SqlConnection("Data Source = LAPTOP-KJLU9H2F\\SQLEXPRESS; Initial Catalog = 'Автосалон'; Integrated Security = True");
                connection.Open();
                SqlCommand command = connection.CreateCommand();
                command.CommandText = sqlInsert;
                command.Parameters.Add("@VIN", SqlDbType.VarChar, 20).Value = VIN.Text;
                command.Parameters.Add("@Заказ", SqlDbType.Int).Value = zakaz;
                command.Parameters.Add("@Филиал", SqlDbType.Int).Value = filial;
                SqlCommand cmd = new SqlCommand(sqlInsert, connection);
                cmd.ExecuteNonQuery();

60be2a688f27c413376277.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-06-07
@a63826ndrew

1. After SET there should be a list of changeable fields with values ​​of the form SET field1 = 'value1', field2 = @value2
2, 3. You create a command command, fill in its parameters, then create a new cmd command, which you try to call without filling in its parameters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question