リンク
上記サイトのプログラムを見ていてわからないところがあります。
下記コードの//SQLの準備 の部分がなにをしているのか具体的にわかりません。できればクラスやメソッドレベルで詳しく解説していただきたいです。
よろしくお願いします。
(C#初心者です。)
using System; using System.Configuration; using System.Data.SqlClient; public void Insert1(string id, string password, string role) { // 接続文字列の取得 var connectionString = ConfigurationManager.ConnectionStrings["sqlsvr"].ConnectionString; using (var connection = new SqlConnection(connectionString)) using (var command = connection.CreateCommand()) { try { // データベースの接続開始 connection.Open(); // SQLの準備 command.CommandText = @"INSERT INTO T_USER (ID, PASSWORD, ROLE_NAME) VALUES (@ID, @PASSWORD, @ROLE_NAME)"; command.Parameters.Add(new SqlParameter("@ID", id)); command.Parameters.Add(new SqlParameter("@PASSWORD", password)); command.Parameters.Add(new SqlParameter("@ROLE_NAME", role)); // SQLの実行 command.ExecuteNonQuery(); } catch (Exception exception) { Console.WriteLine(exception.Message); throw; } finally { // データベースの接続終了 connection.Close(); } } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/06 09:49