0

VB.NET で 1 つのプロシージャで 1 つの開いている接続で 2 つのコマンド オブジェクトを使用できますか?

4

2 に答える 2

2

はい、できます。コマンド間の接続を閉じない限り、問題なく動作します。

これは C# の例ですが、うまくいくと確信しています。

    using (SqlConnection cn = new SqlConnection("Connection String"))
    {

        SqlCommand cmd1 = new SqlCommand("Command1", cn);
        cmd1.CommandType = CommandType.StoredProcedure;

        SqlCommand cmd2 = new SqlCommand("Command2", cn);
        cmd2.CommandType = CommandType.StoredProcedure;

        cn.Open();

        // Execute cmd1
        // Execure cmd2

    }
于 2009-11-05T09:30:49.010 に答える
2

例; ちょっと疑似ですが、概念を理解する必要があります。

dim cnn as connection 
dim cmd as command 
dim cmd2 as command 
dim str1 as string
dim str2 as string 

cnn.open

cmd.connection = cnn 
cmd.command = str1 
cmd.execute

cmd2.connection = cnn 
cmd2.command = str2
cmd2.execute

cnn.close
于 2009-11-05T09:35:15.110 に答える