SqlCommand 的 In-Out 参数 [英] In-Out Parameter for SqlCommand

查看:24
本文介绍了SqlCommand 的 In-Out 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 = new SqlCommand("aspInsertZipCode", mySqlConnection);
 mySqlCommand.CommandType = CommandType.StoredProcedure;
 mySqlCommand.Parameters.Add("@DataRows", dataStringToProcess.ToString());

解决方案

var pInOut = mySqlCommand.Parameters.Add("@DataRows", dataStringToProcess.ToString());
pInOut.Direction = ParameterDirection.InputOutput;

And then to read the output value after you've executed the command:

// assumes that the parameter is a string and that it could possibly be null
string value = Convert.IsDBNull(pInOut.Value) ? null : (string)pInOut.Value;

这篇关于SqlCommand 的 In-Out 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆