2016-05-30 226 views
-3

时,我不断收到错误“必须声明标量变量”:执行的SQL语句

Must declare the scalar variable.

这里是我的代码。我发现这种奇怪的,因为几乎完全一样的事情,但只有不同的话工作在一个不同的形式。

SqlCommand cmd = new SqlCommand("update tblLogin SET Paswoord = @ww2 where Gebruikersnaam = @Gebruiker and Paswoord = @ww", con); 
command.Parameters.AddWithValue("@Gebruiker", labelAccount.Text); 
command.Parameters.AddWithValue("@ww", txtHuidigWW.Text); 
command.Parameters.AddWithValue("@ww2", txtNieuwWW.Text); 

con.Open(); 
cmd.ExecuteNonQuery(); 
con.Close(); 

MessageBox.Show("De gegevens zijn succesvol opgeslagen."); 
+0

连接线什么的错误?什么变量? – nicomp

+0

@ ww2,我应该发布我的整个代码吗? – Viktor

+5

我不确定我们可以信任你发布的代码......你在第一行有'cmd',然后在后面的行有'command'?这在你的代码中是否真的如此? – sstan

回答

1
     SqlCommand cmd = new SqlCommand("update tblLogin SET Paswoord = @ww2 where Gebruikersnaam = @Gebruiker and Paswoord = @ww", con); 
         cmd.Parameters.AddWithValue("@Gebruiker", labelAccount.Text); 
         cmd.Parameters.AddWithValue("@ww", txtHuidigWW.Text); 
         cmd.Parameters.AddWithValue("@ww2", txtNieuwWW.Text); 

         con.Open(); 
         cmd.ExecuteNonQuery(); 
         con.Close(); 

         MessageBox.Show("De gegevens zijn succesvol opgeslagen."); 

更改命令CMD