C#
1using System; 2using System.Collections.Generic; 3using System.Data; 4using System.Diagnostics; 5using System.Linq; 6using System.Text; 7using System.Threading.Tasks; 8using MySql.Data.MySqlClient; 9using MySqlX.XDevAPI.Relational; 10 11namespace MySQL接続テスト 12{ 13 class Program 14 { 15 static void Main(string[] args) 16 { 17 18 string server = "localhost"; // MySQLサーバホスト名 19 string user = "yness123"; // MySQLユーザ名 20 string pass = "wizard123"; // MySQLパスワード 21 string database = "rirekidb"; // 接続するデータベース名 22 23 string connectionString = string.Format("Server={0};Database={1};Uid={2};Pwd={3}", server, database, user, pass); 24 25 Console.WriteLine(connectionString); 26 try 27 { 28 MySqlConnection connection = new MySqlConnection(connectionString); 29 connection.Open(); 30 Console.WriteLine("MySQLに接続しました!"); 31 MySqlCommand selectCommand = new MySqlCommand("select job_name ,delay_second from rireki;", connection); 32 MySqlDataReader reader = selectCommand.ExecuteReader(); 33 34 35 36 string[] names = new string[reader.FieldCount]; 37 for (int i = 0; i < reader.FieldCount; i++) 38 names[i] = reader.GetName(i); 39 Console.WriteLine(string.Join("\t", names)); 40 41 42 while (reader.Read()) 43 { 44 string[] row = new string[reader.FieldCount]; 45 for (int i = 0; i < reader.FieldCount; i++) 46 row[i] = reader.GetString(i); 47 Console.WriteLine(string.Join("\t", row)); 48 49 } 50 51 Dictionary<string, int> dictionary = new Dictionary<string, int>(); 52 while (reader.Read()) 53 { 54 string[] row1 = new string[reader.FieldCount]; 55 foreach (var item in reader) 56 { 57 Console.WriteLine(dictionary.Add(item));とくにここ 58 } 59 60 61 } 62 63 64 65 // 接続の解除 66 connection.Close(); 67 Console.ReadKey(); 68 } 69 catch (MySqlException me) 70 { 71 Console.WriteLine("ERROR: " + me.Message); 72 Console.ReadKey(); 73 } 74 } 75 } 76}
mysqlから取得したデータをディクショナリーにもたせて各々使いたいのですがやり方が分かりません