在下面的代码中使用SqlCommand
时出现错误,请告知。
try
{
sqlConnection sqlConnection1 = new sqlConnection("Server=.\\SQLEXPRESS;Database=Bazy;Integrated Security=true ");
SqlCommand cmd1 = new SqlCommand("select pass from Users where user1='" + user + "'", sqlConnection1);
SqlDataReader sdr;
sqlConnection1.open();
sdr = cmd1.ExecuteReader();
if (sdr.GetString(0) == tBox_oldPassword.Text)
{
cmd1.CommandText = "update Users set Pass='" + tBox_newPassword.Text + "' where User1='" + tBox_userName.Text + "'";
cmd1.ExecuteNonQuery();
}
else
{
MessageBox.Show("ادخل كلمة السر الحالية.");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
答案 0 :(得分:1)
似乎您将SqlConnection
的输入错误键入为sqlConnection
,然后让Visual Studio(或者可能是ReSharper,因为它倾向于使用throw new NotImplementedException();
作为其生成的方法主体,并且我不确定这是否是VS的默认行为)使用构造函数或open
方法自动为您实现该类,并抛出NotImplementedException
,因为您尚未实现。
更改
sqlConnection sqlConnection1 = new sqlConnection("Server=.\\SQLEXPRESS;Database=Bazy;Integrated Security=true ");
到
SqlConnection sqlConnection1 = new SqlConnection("Server=.\\SQLEXPRESS;Database=Bazy;Integrated Security=true ");
并考虑删除您错误添加的sqlConnection
类。