【发布时间】:2018-06-26 01:37:38
【问题描述】:
我的代码执行成功,它也更新了数据库中的表,但它仍然返回我指定的错误,它失败了。
这是我的代码:
private void button2_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(textBox1.Text) && !string.IsNullOrEmpty(textBox2.Text) && !string.IsNullOrEmpty(textBox3.Text) && !string.IsNullOrEmpty(textBox4.Text) && !string.IsNullOrEmpty(comboBox1.Text) && !string.IsNullOrEmpty(comboBox2.Text))
{
if (textBox3.Text == textBox4.Text)
{
SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-TAACMGJ\SQLEXPRESS;Initial Catalog=libman;Integrated Security=True");
SqlCommand cmd = new SqlCommand("UPDATE logdat set pass=@pass WHERE uname=@uname AND sec_que=@sec_que AND sec_ans=@sec_ans AND type=@type", con);
cmd.Parameters.AddWithValue("@uname", textBox1.Text);
cmd.Parameters.AddWithValue("@sec_ans", textBox2.Text);
cmd.Parameters.AddWithValue("@pass", textBox3.Text);
cmd.Parameters.AddWithValue("@sec_que", comboBox1.Text);
cmd.Parameters.AddWithValue("@type", comboBox2.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
try
{
DataTable dt = new DataTable();
con.Open();
da.Fill(dt);
cmd.ExecuteNonQuery();
con.Close();
if (dt.Rows.Count > 0)
{
MessageBox.Show("Password Reset Successfull!!");
this.Close();
}
else
{
MessageBox.Show("Password Reset Failed!! Re-Enter Details.");
reset();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
else
{
MessageBox.Show("Password Confirmation Failed!!");
textBox3.Text = "";
textBox4.Text = "";
}
}
else
{
MessageBox.Show("Please Fill All The Details!!");
}
}
【问题讨论】:
-
您遇到什么错误?在哪里?我猜它在咕哝什么类型的东西?
-
密码重置失败!重新输入详细信息。从我的代码中的else语句。但数据库表得到更新
-
我很惊讶它没有抱怨您的查询使用了保留字..
-
@BugFinder:
Type不是保留关键字:docs.microsoft.com/en-us/sql/t-sql/language-elements/… -
我发誓那是..哦,好吧..我去泡那份急需的茶
标签: c# sql sql-server-2008