数据库查询C#无法正常工作

我已经在网上阅读了许多C#的ODBC教程,并且这段代码是唯一没有出错的代码.但是问题是,它什么也没做-.-如何解决?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Data.Odbc;
using System.Data.Sql;
namespace WindowsFormsApplication1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
        string connectionString = "Server=localhost;User       ID=root;Password=****;Database=testing;Port=3306;Pooling=false";
        MySql.Data.MySqlClient.MySqlConnection connection = new MySql.Data.MySqlClient.MySqlConnection(connectionString);

        connection.Open();

        string insertQuery = "ALTER TABLE `user` ADD lol INT (15)";
        MySql.Data.MySqlClient.MySqlCommand myCommand = new MySql.Data.MySqlClient.MySqlCommand(insertQuery);
        connection.Close();
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
}
}

解决方法:

您需要执行以下命令:

myCommand.ExecuteNonQuery();
上一篇:ODBC快速入门


下一篇:c-寻求有关简单内存数据库*服务器*的建议(无需持久性)