using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Land.BaseClass;namespace Land
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
} private void Login_Load()
{
txtName.Focus();
} private void txtPwd_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
btnSubmit_Click(sender, e);
}
} private void btnSubmit_Click(object sender, EventArgs e)
{
if (txtName.Text == "")
{
MessageBox.Show("请输入用户名", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
if (txtPwd.Text == "")
{
MessageBox.Show("请输入密码", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
SqlConnection conn = BaseClass.DBcon.Access();//创建数据库连接对象
conn.Open();
string find = "select * from Land where UserName='" + txtName + "' and Pass_word='" + txtPwd + "'";//用户验证查询语句
DataSet ds = new DataSet();//创建数据集
SqlDataAdapter adapter = new SqlDataAdapter(find, conn);//创建数据库适配器对象
adapter.Fill(ds);//填充数据集
if (ds.Tables[0].Rows.Count > 0)
{
Main main = new Main();
main.Show();
}
else
MessageBox.Show("用户名密码错误");
}
}
}
}
}
这个是类DB.con的代码using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;namespace Land.BaseClass
{
class DBcon
{
public static SqlConnection Access()
{
return new SqlConnection("server=(local); database=Land; uid=sa");
}
}
}
显示的错误是错误:
“Login_Load”的重载均与委托“System.EventHandler”不匹配这个是Login.designer.cs的显示的代码,标记的错误在最下面的
this.Load += new System.EventHandler(this.Login_Load);namespace Land
{
partial class Login
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows Form Designer generated code /// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.txtName = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.txtPwd = new System.Windows.Forms.TextBox();
this.btnSubmit = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(40, 62);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(53, 12);
this.label1.TabIndex = 0;
this.label1.Text = "用户名:";
//
// txtName
//
this.txtName.Location = new System.Drawing.Point(110, 53);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(100, 21);
this.txtName.TabIndex = 1;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(42, 101);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(41, 12);
this.label2.TabIndex = 2;
this.label2.Text = "密码:";
//
// txtPwd
//
this.txtPwd.Location = new System.Drawing.Point(110, 98);
this.txtPwd.Name = "txtPwd";
this.txtPwd.Size = new System.Drawing.Size(100, 21);
this.txtPwd.TabIndex = 3;
//
// btnSubmit
//
this.btnSubmit.Location = new System.Drawing.Point(44, 189);
this.btnSubmit.Name = "btnSubmit";
this.btnSubmit.Size = new System.Drawing.Size(75, 23);
this.btnSubmit.TabIndex = 4;
this.btnSubmit.Text = "登录";
this.btnSubmit.UseVisualStyleBackColor = true;
this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(160, 189);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(75, 23);
this.btnExit.TabIndex = 5;
this.btnExit.Text = "取消";
this.btnExit.UseVisualStyleBackColor = true;
//
// Login
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnSubmit);
this.Controls.Add(this.txtPwd);
this.Controls.Add(this.label2);
this.Controls.Add(this.txtName);
this.Controls.Add(this.label1);
this.Name = "Login";
this.Text = "Login";
this.Load += new System.EventHandler(this.Login_Load);
this.ResumeLayout(false);
this.PerformLayout(); } #endregion private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtName;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtPwd;
private System.Windows.Forms.Button btnSubmit;
private System.Windows.Forms.Button btnExit;
}
}
刚入手C#,不是很懂怎么处理这个问题,该怎么改
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货