In-Out Parameter for SqlCommand

前端 未结 4 478
一整个雨季
一整个雨季 2020-12-11 15:44

I have the following parameter for SqlCommand. How do I make it to both in and out the paramter value for the Stored Procedure.

 SqlCommand mySqlCommand = ne         


        
4条回答
  •  离开以前
    2020-12-11 16:33

    SqlParameter has a Direction enumeration. Set this value.

    Then use the SqlCommand.Parameters.Add that takes a SqlParameter.

    Parameter direction:

    http://msdn.microsoft.com/en-us/library/system.data.parameterdirection.aspx

    You then pull the value out after having called ExecuteNonQuery (for example), by getting the Value from the parameter out of the command collection:

    myCommand.Parameters["@paramName"].Value

    Can't remember, but I think there is a string indexer on that.

    Alternatively, there is this one liner:

    myCommand.Parameters.AddWithValue("@paramName", value).Direction = ParameterDirection.InputOutput;

提交回复
热议问题