Answer the question
In order to leave comments, you need to log in
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 Номер_филиала = @Филиал";
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();
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();
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question