C#'LBImqP.Form1'不包含'Form1_Load'的定义

时间:2017-11-17 20:58:18

标签: c#

请有人帮助我,我坚持这个错误,我现在不知道如何解决它。

错误代码:'LBImqP.Form1'不包含'Form1_Load'的定义,也没有找到接受类型'LBImqP.Form1'的第一个参数的扩展方法'Form1_Load'(你是否缺少using指令或者装配参考?)

这是我的代码:

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 MySql.Data.MySqlClient;

namespace LBImqP
{
    public partial class Form1 : Form
    {
        MySqlConnection con = new MySqlConnection(@"Data Source=localhost;port=3306;Initial Catalog=lbimqp;User ID=root;password='server1234'");
        int i;
        public Form1()
        {
            InitializeComponent();
        }

        private void login_Click(object sender, EventArgs e)
        {
            i = 0;
            con.Open();
            MySqlCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "select * from login where username='"+user.Text+"' and password='"+pass.Text+"'";
            cmd.ExecuteNonQuery();
            DataTable dt = new DataTable();
            MySqlDataAdapter da = new MySqlDataAdapter(cmd);
            da.Fill(dt);
            i = Convert.ToInt32(dt.Rows.Count.ToString());

            if (i == 0)
            {
                wrong.Text = "Benutzername oder Passwort ist falsch!";
            }
            else
            {
                this.Hide();
                mainscreen ms = new mainscreen();
                ms.Show();
            }
            con.Close();
        }
        private void pass_TextChanged(object sender, EventArgs e)
        {
            pass.PasswordChar = '*';
        }

        private void exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

我在button1_Click和Form1_Load

中收到此错误 当有人能帮助我时,这将是非常棒的。

1 个答案:

答案 0 :(得分:0)

看起来您在Form1设计器中使用事件处理程序Form1_Load附加事件,并且事件处理程序未在Form1类中定义。

或者设计器类和表单类的名称空间不相同。