これも覚書、前にもくらった記憶が(苦笑)
ストアドからOutputされた値をCommandItemで受け取ったら、Connect Close後にしか
中身が見えないことに注意!
' Assumes that connection is a valid SqlConnection object. Dim command As SqlCommand = New SqlCommand("SampleProc", connection) command.CommandType = CommandType.StoredProcedure Dim parameter As SqlParameter = command.Parameters.Add( _ "RETURN_VALUE", SqlDbType.Int) parameter.Direction = ParameterDirection.ReturnValue parameter = command.Parameters.Add( _ "@InputParm", SqlDbType.NVarChar, 12) parameter.Value = "Sample Value" parameter = command.Parameters.Add( _ "@OutputParm", SqlDbType.NVarChar, 28) parameter.Direction = ParameterDirection.Output connection.Open() Dim reader As SqlDataReader = command.ExecuteReader() Console.WriteLine( _ "{0}, {1}", reader.GetName(0), reader.GetName(1)) Do While reader.Read() Console.WriteLine( _ "{0}, {1}", reader.GetInt32(0), reader.GetString(1)) Loop reader.Close() connection.Close() Console.WriteLine( _ " @OutputParm: {0}", command.Parameters("@OutputParm").Value) Console.WriteLine( _ "RETURN_VALUE: {0}", command.Parameters("RETURN_VALUE").Value)