本文介绍了如何修复此代码?错误必须声明标量变量“@TxtId”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 这是代码: this is the code :{ 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); } } } 当我调试软件并点击删除按钮它说必须声明标量变量@TxtId。 如何解决?when i debug software and click on delete button it say's must declare the scalar variable "@TxtId".how to fix it ?推荐答案 using (SqlCommand command = new SqlCommand("Delete Movies WHERE Id_Movies = @Id", connection)){ 注意:确保在元素中传递有效值 TxtId 希望,它有帮助:)Note: Make sure that you are passing a valid value in the element TxtIdHope, it helps :) 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();} 删除sql语法是 delete sql syntax is DELETE FROM table_nameWHERE some_column=some_value; 并且还提供正确的参数名称。And also give correct parameter name. using (SqlCommand command = new SqlCommand("Delete Movies WHERE Id_Movies = @Id", connection)) 而不是@TxtId.text 问候 Aravind instead of @TxtId.textRegards Aravind 这篇关于如何修复此代码?错误必须声明标量变量“@TxtId”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-28 10:46