简体   繁体   中英

how to create c# exe?

How to create a exe file for this C# program. I did try to create an exe file but some error occurred the error is,

'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);
            }
        }
    }
}

You probably at one point tried to write code that executes on the form load, and then deleted the load method. The error is coming from the fact that there is still a reference to that method which no longer exists.

The solution is simply to double-click on the error in Visual Studio and delete the lines that are causing you problems, which will be the ones that reference the now nonexistent method.

You're missing an event handler, it seems, that's probably specified in the designer. Either remove the reference to it, or define it, probably something like this:

save_Load(object sender, EventArgs e) {

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM