0

如何为此 C# 程序创建 exe 文件。我确实尝试创建一个 exe 文件,但发生了一些错误,错误是,

'WindowsFormsApplication11.save' does not contain a definition for 'save_Load' and no extension method 'save_Load' accepting a first argument of type 'WindowsFormsApplication11.save' could be found (are you missing a using directive or an assembly reference?)

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

namespace WindowsFormsApplication11
{
    public partial class save : Form
    {
        public save()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string myConnection = "datasource=localhost;port=3306;username=root;Password=root";
            string query = "insert into store_data.item_details (item_id,item_name,item_qty,item_price) values('" + this.id_txt.Text + "','" + this.name_txt.Text + "','" + this.qty_txt.Text + "','" + this.price_txt.Text + "');";
            MySqlConnection connection = new MySqlConnection(myConnection);
            MySqlCommand cmdsave = new MySqlCommand(query, connection);

            MySqlDataReader dataReader;

            try
            {
                connection.Open();
                dataReader = cmdsave.ExecuteReader();
                MessageBox.Show("your Data has been saved ");

                while (dataReader.Read())
                {
                }

                connection.Close();
            }
            catch (Exception excep)
            { 
                MessageBox.Show(excep.Message);
            }
        }
    }
}
4

2 回答 2

2

您可能有一次尝试编写在表单加载时执行的代码,然后删除了加载方法。该错误来自这样一个事实,即仍然存在对该方法的引用,该方法不再存在。

解决方案是简单地双击 Visual Studio 中的错误并删除导致问题的行,这些行将引用现在不存在的方法。

于 2013-06-11T10:31:52.187 回答
0

您似乎缺少一个可能在设计器中指定的事件处理程序。要么删除对它的引用,要么定义它,可能是这样的:

save_Load(object sender, EventArgs e) {

}
于 2013-06-11T10:32:59.553 回答