Click here to Skip to main content
15,891,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is the code :

C#
{
               using (SqlConnection connection = CreateConnection())
               using (SqlCommand command = new SqlCommand("Delete Movies WHERE Id_Movies = @TxtId.text", connection))
               {
                   command.Parameters.AddWithValue("@Name", TxtName.Text);
                   command.Parameters.AddWithValue("@Director", TxtDirector.Text);
                   command.Parameters.AddWithValue("@Year", TxtYear.Text);
                   command.Parameters.AddWithValue("@Type", TxtType.Text);
                   command.Parameters.AddWithValue("@Id", TxtId.Text);

                   try
                   {
                       connection.Open();
                       command.ExecuteNonQuery();

                       MessageBox.Show("Deleted successfully.");
                       Clear();
                   }
                   catch (SqlException ex)
                   {
                       MessageBox.Show(ex.Message);
                       
                   }
               }
           }


when i debug software and click on delete button it say's must declare the scalar variable "@TxtId".

how to fix it ?
Posted
Updated 22-Jul-15 18:59pm
v2
Comments
V Senthil Kumar 23-Jul-15 0:30am    
can you try where Id_Movies='"+txtid.Text+"',con
brandon1999 23-Jul-15 0:39am    
i try that but get error alot.

You have assigned wrong variable for one of the parameter. Try this-
C#
using (SqlCommand command = new SqlCommand("Delete Movies WHERE Id_Movies = @Id", connection))
{

Note: Make sure that you are passing a valid value in the element TxtId

Hope, it helps :)
 
Share this answer
 
v2
Comments
brandon1999 23-Jul-15 1:12am    
that is work . thank you so much.
C#
using (SqlConnection connection = CreateConnection())
using (SqlCommand command = new SqlCommand("Delete from Movies WHERE Id_Movies = @Id", connection))
{
   command.Parameters.AddWithValue("@Id", TxtId.Text);
   connection.Open();
   command.ExecuteNonQuery();
}


delete sql syntax is

SQL
DELETE FROM table_name
WHERE some_column=some_value;


And also give correct parameter name.
 
Share this answer
 
Hi Try to pass like this
VB
using (SqlCommand command = new SqlCommand("Delete Movies WHERE Id_Movies = @Id", connection))


instead of @TxtId.text




Regards
Aravind
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900