C# · 12月 26, 2021

c# – SqlCommand的输入参数

我有sqlCommand的以下参数.如何使其存入和存储存储过程的参数值. 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;

然后在执行命令后读取输出值:

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