-1

テキスト ファイル データをディレクトリから SQL の特定のデータベース フィールドに取得したいと考えています。コードは次のとおりです。

try
{
    FolderBrowserDialog fBrowser = new FolderBrowserDialog();
    //create instance of folder browser to navigate to desired folder to compress files
    DialogResult result = fBrowser.ShowDialog();
    //process this if user clicks OK button
    if (result == DialogResult.OK)
    {
       //string strPath stores chosen path
       strPath = fBrowser.SelectedPath;
       //put that path in the textbox1
       txtSource.Text = strPath;
    }
    //set current directory to be the one you navigated to 
    //(this is also the folder that will store the compressed file)
    Directory.SetCurrentDirectory(strPath);
    //get contents of directory stored in "strPath"
    DirectoryInfo di = new DirectoryInfo(strPath);
    //create array that holds requested files from folder stored in "di" variable
    DirectoryInfo[] rgFiles = di.GetDirectories("*.*");
    //move through DirectoryInfo array and store in new array of fi
    foreach (DirectoryInfo fi in rgFiles)
    {
       checkedListBox1.Items.Add(fi.Name); //add folders located into listbox
    }
}

ここで、ディレクトリには no が含まれています。画像と txt ファイルの場合、チェックリスト ボックスを選択すると、txt ファイルからのすべてのデータが、それらのデータ型に関連する特定の SQL データベースに追加されます。誰でも私を助けることができます

4

1 に答える 1

0

ディレクトリにファイルがあるかどうかを確認するには、「ディレクトリ」と呼ばれる System.IO クラスとそのメソッド「GetFiles」を使用できます。ディレクトリのパスを渡すだけです。そのディレクトリ内のファイルの文字列配列を返します。詳細はこちら:

http://msdn.microsoft.com/en-us/library/07wt70x2.aspx

最善の方法は、着信要求を処理できるストアド プロシージャをデータベースに作成し、データを正しいテーブルに挿入することです。Sql-Server ストアド プロシージャの概要を次に示します。

http://msdn.microsoft.com/en-us/library/aa174792(v=sql.80).aspx

次に、C# コードでデータベースへの接続を作成する必要があります。

http://msdn.microsoft.com/en-us/library/s4yys16a(v=vs.71).aspx

最後に、作成したばかりの接続を使用してストアド プロシージャを呼び出し、C# コードからパラメーターを渡す必要があります。これについては、StackOverflow で何度も回答されています。

C# プログラム内でストアド プロシージャを実行する方法

于 2013-03-19T09:05:00.150 に答える