LoginSignup
0
0

More than 1 year has passed since last update.

.Net 6: C# で MariaDB の Update

Last updated at Posted at 2022-08-09

プロジェクトの作成

mkdir Update01
cd Update01
dotnet new console
dotnet add package MySql.Data --version 8.0.30

フォルダー構造

$ tree -L 1
.
├── Program.cs
├── Update01.csproj
├── mysql_manipulate.cs
└── obj
Program.cs
// -------------------------------------------------------------------
/*
	Program.cs

					Aug/09/2022


*/
// -------------------------------------------------------------------
using	System;
using	MySql.Data.MySqlClient;

// -------------------------------------------------------------------
class maria_update
{
// -------------------------------------------------------------------
static void Main (string[] args)
{
	Console.WriteLine ("*** 開始 ***");

	string	id_in = args[0];
	int	population_in = int.Parse (args[1]);

	string server = "localhost";
	string str_db = "city";
	string user = "scott";
	string password = "tiger123";

	string str_connect = "Server=" + server + 
		";User Id=" + user + ";Password=" + password +
		";Database=" + str_db + ";";
 
	MySqlConnection connection = new MySqlConnection (str_connect);
	connection.Open ();

	mysql_manipulate.mysql_update_proc (connection,id_in,population_in);

	connection.Close ();


	Console.WriteLine ("*** 終了 ***");
}

// -------------------------------------------------------------------
}

// -------------------------------------------------------------------

mysql_manipulate.cs はこちら
.Net Core: C# で MariaDB の Create

実行結果

$ dotnet run t3326 17895600
*** 開始 ***
2022-08-09 14:24:19
UPDATE cities SET population = 17895600 , date_mod = '2022-08-09 14:24:19' WHERE id = 't3326'
rowsAffected = 1
*** 終了 ***
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