-6

您好,我想与存储在服务器上的 mysql 数据库进行远程连接,并且我想在控制台上显示该数据库的所有表名,该怎么做?

关于数据库的信息是这样的

 server = "50.62.82.40";database = "db_admin"; uid = "db_usr";password = "wowow";
4

1 回答 1

-1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data.SqlClient;

namespace ConsoleApplication2
{

    class Program
    {
        public static void Main()
        {
            string myConnectionString = "SERVER=50.62.82.40;" +
                            "DATABASE=db_admin;" +
                            "UID=db_usr;" +
                            "PASSWORD=wowow`enter code here`;";

            MySqlConnection connection = new MySqlConnection(myConnectionString);
            MySqlCommand command = connection.CreateCommand();
            command.CommandText = "SHOW TABLES;";
            MySqlDataReader Reader;
            connection.Open();
            Reader = command.ExecuteReader();
            while (Reader.Read())
            {
                string row = "";
                for (int i = 0; i < Reader.FieldCount; i++)
                    row += Reader.GetValue(i).ToString() + ", ";
                Console.WriteLine(row);
            }
            connection.Close();
            Console.ReadLine();
        }
    }
}
于 2013-03-04T12:19:10.547 回答