0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

cscの作法 その627

Last updated at Posted at 2026-01-15

概要

cscの作法、調べてみた。
練習問題、やってみた。
文字化けで、三日掛かった。

練習問題

mysql.data.dllでwsl1のmysqlに繋げ。

環境

windows10
wsl1
ubuntu18.04
mysql5.7

サンプルコード

using System;
using System.Text;
using MySql.Data.MySqlClient;

public static class mysql {
	public static void Main (string[] args) {
		string server = "localhost";
		string str_db = "mydb";
		string user = "***";
		string password = "***";
		string str_connect = "Server=" + server + ";User Id=" + user + ";Password=" + password + ";Database=" + str_db + ";charset=utf8mb4";
		MySqlConnection conn = new MySqlConnection(str_connect);
		conn.Open();

		MySqlCommand cmd0 = new MySqlCommand("CREATE TABLE Test(name VARCHAR(40) NOT NULL, name2 VARCHAR(20)) " + "CHARACTER SET utf8", conn);
		cmd0.ExecuteNonQuery();
		Console.WriteLine("create");

		MySqlCommand cmd1 = new MySqlCommand("INSERT INTO Test VALUES('name', '名前')", conn);
		cmd1.ExecuteNonQuery();
		Console.WriteLine("insert");

		MySqlCommand command = new MySqlCommand("SELECT * FROM Test", conn);
		MySqlDataReader reader = command.ExecuteReader();
		while (reader.Read())
		{
			for (int i = 0; i < reader.FieldCount; i++)
			{
				Console.Write("{0} \t", reader[i]);
			}
			Console.WriteLine();
		}
		Console.WriteLine("select");

		MySqlCommand cmd2 = new MySqlCommand("DROP TABLE Test", conn);
		cmd2.ExecuteNonQuery();
		Console.WriteLine("drop");

		conn.Close();
	}
}


実行結果

>mysql0
name    名前
name    名前
name    名前
name    名前
name    名前
select

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?