Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 运行MySQL数据库连接C时出现问题#_C#_Mysql_Database - Fatal编程技术网

C# 运行MySQL数据库连接C时出现问题#

C# 运行MySQL数据库连接C时出现问题#,c#,mysql,database,C#,Mysql,Database,我正在尝试运行到数据库的MySQL连接。代码是正确的,但是我无法使类运行 static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles();

我正在尝试运行到数据库的MySQL连接。代码是正确的,但是我无法使类运行

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
        Application.Run(new DBInfo());
    }
}
DBInfo只是在一个单独的脚本中初始化应用程序

public DBInfo()
{
    Initialize();
}
你可以做如下的事情

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());
    //Application.Run(new DBInfo()); remove from here
}
您可以从
Form1

public Form1()
{
    try
    {
        DBInfo db = new  DBInfo();
        // do stuff with DBInfo object like db.GetConnection() etc...
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}

方法,除表单外,参数为ApplicationContext。你的DBInfo方法没有返回任何一个

你确定要传递该DBInfo以运行吗?嗯,我以前从未在应用程序中真正使用过数据库,所以我正在测试它。我真的不知道如何处理这个问题。嗨,我认为这是可行的,但现在应用程序崩溃了。lol“DBtest已停止工作”哦,我确实删除了(Application.Run(new DBInfo())你需要一些异常处理。检查异常,让你知道发生了什么。天哪……结果令人无法原谅,你不会碰巧知道任何使用MySQL和应用程序的教程吧?
public Form1()
{
    try
    {
        DBInfo db = new  DBInfo();
        // do stuff with DBInfo object like db.GetConnection() etc...
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}