C# 运行MySQL数据库连接C时出现问题#
我正在尝试运行到数据库的MySQL连接。代码是正确的,但是我无法使类运行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();
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());
}
}