连接数据库的登陆程序,提示错误 CS0123:“button1_Click”没有与委托“EventHandler”匹配的重载,问题出在CU.Desinger.cs这一段代码如下:
//
// button1
//
this.button1.Location = new System.Drawing.Point(106, 322);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(94, 29);
this.button1.TabIndex = 7;
this.button1.Text = "确定";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
button_Click逻辑代码如下:
```c#
private void button1_Click(object sender, EventArgs e, SqlDataReader sqlDataReader)
{
if (textBox1.Text == "")
MessageBox.Show("注册失败,用户名不得为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
else if (textBox2.Text == "")
MessageBox.Show("注册失败,密码不得为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
else if (textBox3.Text != textBox2.Text)
MessageBox.Show("注册失败,第二次输入的密码错误!请重新输入!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
{
string connString = @"Data Source=LAPTOP-MQ5N6G1O\SQLEXPRESS;Initial Catalog=database;Integrated Security=True;MultipleActiveResultSets=True";
SqlConnection conn = new SqlConnection(connString);
conn.Open();
string sql = String.Format("select username from adminlogin where username = '{0}'", textBox1.Text);
SqlCommand command = new SqlCommand(sql, conn);
int i = 0;
for (i = 0; sqlDataReader.Read(); i++) { }
if (i > 0)
{
MessageBox.Show("错误!用户已存在!","错误",MessageBoxButtons.OK, MessageBoxIcon.Error);
sqlDataReader.Close();
}
else
{
string sql1 = String.Format("insert into adminlogin(username,password) values('{0}','{1}')",textBox1.Text,textBox2.Text);
SqlCommand command1 = new SqlCommand(sql1, conn);
int j = command1.ExecuteNonQuery();
if (j > 0)
{
MessageBox.Show("注册成功!", "成功");
this.DialogResult = DialogResult.Retry;
this.Close();
}
}
conn.Close();
}
}
}
}
希望各位可以帮助一下我,我刚写C#,初来乍到,不熟悉,感谢各位!
你这个buttonClick是button控件自带的方法,参数是没有SqlDataReader这个的,只有object sender, EventArgs e,而你程序的其他地方又没有重写buttonclick这个方法,当然会报错。
你可以把SqlDataReader放在外面,作为全局变量,在buttonclick这个方法里直接调用就可以了。