如何创建c#exe?

时间:2013-06-11 10:27:37

标签: c# mysql exe

如何为此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);
            }
        }
    }
}

2 个答案:

答案 0 :(得分:3)

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

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

答案 1 :(得分:0)

你似乎错过了一个事件处理程序,它可能是在设计器中指定的。删除对它的引用,或者定义它,可能是这样的:

save_Load(object sender, EventArgs e) {

}