2009年8月24日月曜日

C# Datasetで設定されたコンボボックスの選択された内容を取得

コンボボックス cbo01 のデータソースが
this.cbo01.DataSource = this.Dataset01BindingSource;
のとき

System.Data.DataRowView view01 = (DataRowView)this.cbo01.SelectedItem;
と書くことで、view01にレコードが保存される

たとえば0番目のカラムの内容を表示したければ
MessageBox.Show(view01.Row.ItemArray[0].ToString());

2009年8月21日金曜日

C# コンボボックスを編集できなくする

コンボボックスのDropDownStyleプロパティを「DropDownList」にする

2009年8月20日木曜日

C# 変数等のデータ型を変更する

[C#]
//文字列をint型に変換
int i = int.Parse("100");

//文字列をlong型に変換
long l = long.Parse("100");

//文字列をfloat型に変換
float f = float.Parse("100.1");

//文字列をdouble型に変換
double d = double.Parse("100.1");

//文字列をbool型に変換
bool b = bool.Parse("True");

C#でアプリケーションを終了させる

C# でアプリケーションを終了させるには System.Environment.Exit() を使う。

Environment.Exit(0);

http://sonic64.com/2006-05-07.html

2009年8月17日月曜日

C# pathからファイル名を得る

// getfilename.cs

using System;
using System.IO;

public class GetFileName {
static void Main() {
string path1 = @"c:\windows\system32\notepad.exe";
string file1 = Path.GetFileName(path1);
Console.WriteLine(file1); // 出力例:notepad.exe

string path2 = "c:notepad.exe";
string file2 = Path.GetFileName(path2);
Console.WriteLine(file2); // 出力例:notepad.exe

string path3 = "http://www.atmarkit.co.jp/index.html";
string file3 = Path.GetFileName(path3);
Console.WriteLine(file3); // 出力例:index.html
}
}

C# 設定を使用する

// 設定する
ソリューションエクスプローラー > prorerties > 設定
で設定した変数を呼び出す

// 呼び出す
Properties.Settings.Default.hensu1

// 参照
http://msdn.microsoft.com/ja-jp/library/aa730869%28VS.80%29.aspx

C# ファイル関連

//C:\test.txtをC:\test1.txtに移動
//移動元と移動先が同じでも、例外はスローされない
//C:\test1.txtがすでにあるときは、例外がスローされる
System.IO.File.Move(@"C:\test.txt", @"C:\test1.txt");

//C:\test.txtをC:\test1.txtにコピー
//第3項にtrueを指定することにより、上書きを許可
System.IO.File.Copy(@"C:\test.txt", @"C:\test1.txt", true);

//C:\test.txtを削除
//指定したファイルが存在しなくても例外はスローされない
System.IO.File.Delete(@"C:\test.txt");

//属性の取得(FileAttributes列挙体を返す)
Console.WriteLine(System.IO.File.GetAttributes(@"C:\test.txt"));
//読み取り専用属性があるか調べる
if ((System.IO.File.GetAttributes(@"C:\test.txt") &
System.IO.FileAttributes.ReadOnly) ==
System.IO.FileAttributes.ReadOnly)
Console.WriteLine("読み取り専用属性があります。");

//作成日時の取得(DateTime値を返す)
Console.WriteLine(System.IO.File.GetCreationTime(@"C:\test.txt"));
//更新日時の取得(DateTime値を返す)
Console.WriteLine(System.IO.File.GetLastWriteTime(@"C:\test.txt"));
//アクセス日時の取得(DateTime値を返す)
Console.WriteLine(System.IO.File.GetLastAccessTime(@"C:\test.txt"));

//属性の設定
//読み取り専用属性を追加する
System.IO.File.SetAttributes(@"C:\test.txt",
System.IO.File.GetAttributes(@"C:\test.txt") |
System.IO.FileAttributes.ReadOnly);
//読み取り専用属性を削除する
System.IO.File.SetAttributes(@"C:\test.txt",
System.IO.File.GetAttributes(@"C:\test.txt") ^
System.IO.FileAttributes.ReadOnly);

//作成日時の設定(今の時間にする)
System.IO.File.SetCreationTime(@"C:\test.txt", DateTime.Now);
//更新日時の設定
System.IO.File.SetLastWriteTime(@"C:\test.txt", DateTime.Now);
//アクセス日時の設定
System.IO.File.SetLastAccessTime(@"C:\test.txt", DateTime.Now);

// C:\test.txtが存在するか調べる
if (!System.IO.File.Exists(@"C:\test.txt"))
{
Console.WriteLine("fileがないっす");
}

2009年8月10日月曜日

SQLサーバーのER(SI Object Browser)

SQLServerのIDENTITY型の初期値、増分などを指定する
①データ型に数値型(INTなど)を選択します。
②デフォルト値にて「IDENTITY(1, 1)」を選択し、初期値、増分値を変更します。

タイムスタンプ
①データ型にDATETIME
②デフォルト値に「(getdate())」

ユーザー名
①データ型にNVARCHAR
②デフォルト値に「(user_name())」

ホスト名
①データ型にNVARCHAR
②デフォルト値に「(host_name())」

2009年8月7日金曜日

C#の特殊ファイル

特殊フォルダ
Environment.GetFolderPath(Environment.SpecialFolder.Templates)

http://www.ipentec.com/document/document.aspx?page=csharp-special-folder
http://msdn.microsoft.com/ja-jp/library/system.environment.specialfolder%28VS.80%29.aspx


実行フォルダ
Application.StartupPath

C#で連想配列

Hashtableってのを使うようだ

using System.Collections;
private void Test01()
{
Hashtable ht = new Hashtable();
ht["Sunday"] = "日曜日";
ht["Monday"] = "月曜日";
}


http://www.atmarkit.co.jp/fdotnet/dotnettips/125hashtable/hashtable.html

2009年8月6日木曜日

T-SQLのデバッグ

SQLserverとVisual studio のリモート デバッグをセットアップする

1 サーバーにリモート デバッグ コンポーネントをインストール
rdbgsetup.exe をサーバーにインストール
SQLserver2005でないときは VS2005 のDVDの R:\x86 以下にある
SQLserver2005のときは既に入っている

2 サーバでリモート デバッグのアクセス許可を設定
windows認証にして、デバッグを行うクライアントのユーザーを sysadminにする
management studioの [サーバー名][セキュリティ] [ログイン]

3 サーバーでリモートデバッグモニタを実行する
スタートメニューからでOK
説明が重要!!

4 サーバーでリモートバッグモニタのアクセス許可を変更する
ツール>オプション

5 クライアントでプロセスにアタッチする
VSのツール>プロセスにアタッチ で修飾子に3の説明をみて入力
選択可能なプロセスが出てくるのでVisual Studio リモートデバッグモニタを選択する

6 クライアントでストアドプロシージャにステップインする
サーバーエクスプローラで該当するストアドプロシージャを右クリックして ストアドプロシージャにステップイン


http://msdn.microsoft.com/ja-jp/library/bt727f1t%28VS.80%29.aspx

2009年8月5日水曜日

SQLサーバのフォワードエンジニアリング (SI Object Browser ER)

SI Object Browser ER

SQLサーバのフォワードエンジニアリング

データベース>フォワードエンジニアリング で実行しようとすると
「ntwdblib.dllが足りない」
とのお言葉

1. ダウンロード
http://jp.dll-download-system.com/z/n-dlls-not-system-/ntwdblib.dll/details.html

2. 溶かして、'windows\system'にコピー
\C:\WINDOWS\system32\ にコピーした