32ビット用 : %windir%\Microsoft.NET\Framework\v4.0.30319 64ビット用 : %windir%\Microsoft.NET\Framework64\v4.0.30319 以下64ビット環境です。 ※ Windows10 でも動作していますが、以下のメッセージが出力されます
This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version.csc.exe は、c# 用のコンパイラです。面倒な場所ではあるので、以下のスクリプトで簡単にプロンプトが作成できます
<JOB> <RESOURCE id="commandList"> <![CDATA[ mode con: cols=120 set PATH=%windir%\Microsoft.NET\Framework64\v4.0.30319;%PATH% prompt C#$G ]]> </RESOURCE> <OBJECT id="WshShell" progid="WScript.Shell" /> <OBJECT id="Fso" progid="Scripting.FileSystemObject" /> <SCRIPT language=VBScript> ' *********************************************************** ' 処理開始 ' *********************************************************** strPath = WScript.ScriptFullName Set obj = Fso.GetFile( strPath ) Set obj = obj.ParentFolder WshShell.CurrentDirectory = obj.Path aData = Split( GetInline( "commandList" ), vbCrLf ) strCommand = "cmd.exe /k " & aData(0) For I = 1 to Ubound( aData ) strCommand = strCommand & "&" & aData(I) Next Call WshShell.Run( strCommand, 3 ) ' *********************************************************** ' 関数 ' *********************************************************** Function GetInline( strName ) GetInline = RegTrim( getResource( strName ) ) & vbCrLf End Function Function RegTrim( strValue ) Dim regEx, str Set regEx = New RegExp regEx.IgnoreCase = True regEx.Pattern = "^[ \s]+" str = regEx.Replace( strValue, "" ) regEx.Pattern = "[ \s]+$" RegTrim = regEx.Replace( str, "" ) End Function </SCRIPT> </JOB>
VBScript で記述されており、通常エクスプローラから実行すると最大化ウインドウでコマンドプロンプトが開くように作成してあります。 コマンドプロンプトからは、csc ソースコード.cs と入力するだけで基本的なビルドはすぐできます。 sample.cs
using System; using System.IO; // ******************************************************** // 実行 // ******************************************************** public class App { public static void Main() { // PATH 環境変数取得 String strEnv = Environment.GetEnvironmentVariable( "PATH" ); // 配列定義 String delimStr = ";"; Char[] delimiter = delimStr.ToCharArray(); String[] split = null; // トークン分割 split = strEnv.Split( delimiter ); // ソート Array.Sort( split, split.GetLowerBound(0), split.Length ); // 書き込み try { StreamWriter OutFile = new StreamWriter( @".\result.txt", false ); foreach (String strValue in split) { OutFile.WriteLine( strValue ); } OutFile.Flush(); OutFile.Close(); } catch( Exception e ) { Console.WriteLine("エラーの内容 : {0}", e.ToString()); } } }
オプションは csc /? で表示されます。 mysql.cs( ODBC アクセス )
using Microsoft.VisualBasic; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Data.Odbc; public class App { // ******************************************************** // MySQL / System.Data.Odbc // ******************************************************** public static void Main() { string myConnectString = "Driver={MySQL ODBC 5.3 Unicode Driver};" + "SERVER=localhost;" + "DATABASE=lightbox;" + "UID=root;" + "PWD=password"; OdbcConnection myCon = new OdbcConnection(); myCon.ConnectionString = myConnectString; myCon.Open(); string myQuery = "SELECT 社員マスタ.*,DATE_FORMAT(生年月日,'%Y-%m-%d') as 誕生日" + " from 社員マスタ"; OdbcCommand myCommand = new OdbcCommand(); myCommand.CommandText = myQuery; myCommand.Connection = myCon; OdbcDataReader myReader = default(OdbcDataReader); myReader = myCommand.ExecuteReader(); while (myReader.Read()) { // 文字列 Console.Write(GetValue(myReader, "社員コード") + " : "); Console.Write(GetValue(myReader, "氏名") + " : "); // 整数 Console.Write(GetValue(myReader, "給与") + " : "); // 日付 Console.Write(GetValue(myReader, "作成日") + " : "); Console.Write(GetValue(myReader, "更新日") + " : "); Console.Write(GetValue(myReader, "生年月日") + " : "); Console.Write(GetValue(myReader, "誕生日")); Console.WriteLine(); } myReader.Close(); myQuery = "update 社員マスタ set 生年月日 = '1982/01/01'" + " where 社員コード = '0002'"; Execute(myCon, myQuery); myCon.Close(); myReader.Dispose(); myCon.Dispose(); } // ******************************************************** // 列データ取得 // ******************************************************** public static string GetValue(OdbcDataReader odr, string strName) { string ret = ""; int fld = 0; fld = odr.GetOrdinal(strName); if (odr.IsDBNull(fld)) { ret = ""; } else { ret = odr.GetValue(fld).ToString(); } return ret; } // ******************************************************** // 更新処理 // ******************************************************** public static int Execute(OdbcConnection cn, string SQL) { int ret = 0; OdbcCommand execCommand = new OdbcCommand(); execCommand.CommandText = SQL; execCommand.Connection = cn; try { ret = execCommand.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine(ex.Message); } execCommand.Dispose(); return ret; } }
タグ:C#
|
【VS(C#)の最新記事】
- Replit : cs-list
- C# : Excel の新しいブックのデフォルトのシートのセルに直接値をセットして、オートフィルを Range オブジェクトから実行する
- C#( Form ) : ウインドウ枠の無い吹き出しの作成
- C# のタプル( Visual Studio 2017 でテスト )
- C# : インターネット上の JSON ファイルのフォーマットを クラスとして定義して1行でオブジェクト化して使用する
- C# の文法的文字列処理
- C# : System.Data.Odbc によるデータベースのテーブルからのデータ取得処理( サンプルの SQL は MySQL 用です )
- C# : Excel を データベースとして DataGridView に読み込む
- C# : dynamic 型 による Excel へのアクセス
- C# : フォームを表示せずに、通知領域にアイコンを表示させる常駐プログラム
- Microsoft Access に対してSQLを入力してその結果を DataGridView に表示する最も簡単なコード
- C# : System.Data.Odbc データ取得(SELECT)処理( MySQL ) : ※ using 無し( Dispose 実行 )
- C# : SQL 文を外部テキストにして、String.Format でデータ部分を置き換えて利用する
- C# コンソールアプリを AN HTTPD で実行
- C# : SQLServer( SQLExpress ) の SMO を使用してテーブルの CREATE TABLE 文 を取得する
- C# : DataGridView に TKMP.DLL の IMAP(POP3) で受信したメールを非同期に表示する( 添付ファイルも取得 )
- C# : TKMP.DLLを使った、メール送信テンプレート
- C# と VB.net : TKMP.DLL を使って IMAP でメール本文の一覧を取得する( コンソール )
- C# でDataTable と DataSource を使用して、DataGridView にデータを表示するテンプレート( 行をダブルクリックしてダイアログを表示して行データを処理 )
- (C#) / VS2010 または VS2012 : TKMP.DLL(3.1.2 または 3.1.8)を使った、『さくらインターネット』用メール送信テンプレート