2

我有一个关于 ADOX 的错误,我不知道如何解决。

enter code here public static string[] GetTableExcel(string strFileName)
        {
            string[] strTables = new string[100];
            Catalog sCatalog = new Catalog();
            ADOX.Table sTable = new ADOX.Table();
            MySql.Data.MySqlClient.MySqlConnection sConn = new MySql.Data.MySqlClient.MySqlConnection();
            sConn.Open("server=localhost; Data Source = " + strFileName + ";user id=root;Password=1;database=test;persist security info=False");
            sCatalog.ActiveConnection = sConn;
            if (sCatalog.Tables.Count > 0)
            {
                int item = 0;
                foreach (ADOX.Table tab in sCatalog.Tables)
                {
                    if (tab.Type == "TABLE")
                    {
                        strTables[item] = tab.Name;
                        item++;
                    }
                }
            }
            return strTables;

所述错误是“方法'Open'没有重载需要一个参数。这里有好心人能帮帮我吗?谢谢

4

2 回答 2

2

基本上在这一行:

   sConn.Open("server=localhost; Data Source = " + strFileName + ";user id=root;Password=1;database=test;persist security info=False");

您没有正确调用该函数。open 函数不接受连接字符串。

您应该在创建 MySqlConnection 实例时提供连接字符串,如下所示:

  MySql.Data.MySqlClient.MySqlConnection sConn = new MySql.Data.MySqlClient.MySqlConnection("server=localhost; Data Source = " + strFileName + ";user id=root;Password=1;database=test;persist security info=False");

然后你调用 open 函数如下:

  sConn.Open();

希望有帮助。

于 2012-07-09T08:19:59.227 回答
1

MySql.Data.MySqlClient.MySqlConnection.Open(string connStr) 不可用,您应该调用

MySql.Data.MySqlClient.MySqlConnection sConn = new MySql.Data.MySqlClient.MySqlConnection("server=localhost; Data Source = " + strFileName + ";user id=root;Password=1;database=test;persist security info=False");
sConn.Open();
于 2012-07-09T08:26:11.543 回答