本文介绍了简单编码逻辑的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为winform编写了简单的逻辑代码
当我单击提交而不填写表单时,看到的错误消息是更新失败.我想要在不填写表单时单击提交的错误消息,但是由于输入了passwordword,我的代码也认为是空白
这是我的代码

private void button1_Click(object sender, EventArgs e)
        {
            bool vcom = doublepasword();
            if (!vcom)
            {
                SqlConnection conn = new SqlConnection();
                conn.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\project\sample project\prject xample2 perfect\login\Database1.mdf;Integrated Security=True;User Instance=True";
                try
                {
                    conn.Open();
                    string qry2 = "UPDATE Table1 SET Password =@Password WHERE username=@username";
                    SqlCommand com = new SqlCommand(qry2, conn);
                    com.Parameters.AddWithValue("@username", this.label1.Text);
                    com.Parameters.AddWithValue("@Password", this.textBox1.Text);
                    int result = com.ExecuteNonQuery();
                    if (result > 0)
                    {
                        MessageBox.Show("updated sucesfull \n" + "your new password is: " + textBox1.Text + " thanks for changing your password", "success");
                        this.Hide();
                        login ls = new login();
                        ls.Show();

                    }
                    else
                    {
                        MessageBox.Show("updated failed");
                    }

                }
                catch (Exception)
                {
                    MessageBox.Show("Error with the databse connection");
                }
            }
            else
            {
                MessageBox.Show("error");
            }
        }
        private bool doublepasword()
        {
            if (textBox1.Text != textBox2.Text)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool validation2()
        {
            bool stat1 = doublepasword();
            if (stat1 == true)
            {
                errorProvider1.SetError(textBox2, "password doesnt match");
                pictureBox1.Visible = false;
                label13.Visible = true;
                return true;
            }
            else
            {
                pictureBox1.Visible = true;
                label13.Visible = false;
                errorProvider1.SetError(textBox2, string.Empty);
                return false;
            }
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            validation2();
        }



将"C"标记更改为"C#" [/编辑]

解决方案




这篇关于简单编码逻辑的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 09:57