前面写了一篇《》http://www.cnblogs.com/insus/p/4373605.html ,如果我们需要创建一个带OUTPUT返回值。
实现它,可以先了解一下C#的OUT关键词 打开刚才前面我们写好的SQL DataBase project,添加一个方法: 可复制代码:public static void GetFruitName(out SqlString fruitName, SqlByte fruit_nbr ) { SqlConnection connection = new SqlConnection("Context connection=true"); connection.Open(); SqlCommand command = new SqlCommand(); command.Connection = connection; string sql = "SELECT [FruitName] FROM [dbo].[Fruit] WHERE [Fruit_nbr] = @Fruit_nbr"; command.CommandText = sql; SqlParameter param = new SqlParameter("@Fruit_nbr", SqlDbType.TinyInt); param.Value = fruit_nbr; command.Parameters.Add(param); try { string scalarValue = (string)command.ExecuteScalar(); fruitName = (SqlString)scalarValue; } catch { fruitName = string.Empty; } connection.Close(); }
执行存储过程: