out-parameters

Problem reading out parameter from stored procedure using c#

☆樱花仙子☆ 提交于 2019-12-23 12:04:20
问题 I just come across a strange problem where i cannot retrieve the sql stored procedure out parameter value. I struck with this problem for nearly 2 hours. Code is very simple using (var con = new SqlConnection(connectionString)) { con.Open(); SqlCommand cmd = new SqlCommand("sp_mgsearach", con); cmd.CommandType = CommandType.StoredProcedure; SqlParameter param1 = new SqlParameter("@SearchTerm", SqlDbType.VarChar); param1.Value = searchTerm; param1.Direction = ParameterDirection.Input; cmd

C# - how to pass 'out' parameter into lambda expression

社会主义新天地 提交于 2019-12-21 07:19:09
问题 I have a method with the following signature: private PropertyInfo getPropertyForDBField(string dbField, out string prettyName) In it, I find the associated value prettyName based on the given dbField . I then want to find all properties, if any, that have the name prettyName , so I'm trying to do the following: IEnumerable<PropertyInfo> matchingProperties = getLocalProperties().Where(prop => prop.Name.Equals(prettyName) ); However, this gives the following error: Cannot use ref or out

Java MyBatis stored procedure call with OUT parameters

天大地大妈咪最大 提交于 2019-12-21 05:00:52
问题 First question: I am trying to return one OUT parameter and not a result set with annotations. First, is it even possible? If it is, how would one do this? MyBatis: 3.0.6 Database: SQL Server 2008 Here is an example of the syntax of my method call in the UserDAO: @Select(value= "{ CALL saveUser( " + "#{userId, mode=IN, jdbcType=INTEGER}," + "#{firstname, mode=IN, jdbcType=VARCHAR}," + "#{lastname, mode=IN, jdbcType=VARCHAR}," + "#{message, mode=OUT, jdbcType=VARCHAR}" + ")}") @Options

How to create IN OUT or OUT parameters in Java

∥☆過路亽.° 提交于 2019-12-19 15:25:16
问题 In PL/SQL (or many other languages), I can have IN OUT or OUT parameters, which are returned from a procedure. How can I achieve a similar thing in Java? I know this trick: public void method(String in, String[] inOut, String[] inOut2) { inOut[0] = in; } Where the in parameter represents an IN parameter and the inOut parameter can hold a return value. The convention would be that String[] inOut is an array of inOut.length == 1 . That's kind of clumsy. EDIT Feedback to answers : Other tricks

Why doesn't 'ref' and 'out' support polymorphism?

徘徊边缘 提交于 2019-12-17 02:09:12
问题 Take the following: class A {} class B : A {} class C { C() { var b = new B(); Foo(b); Foo2(ref b); // <= compile-time error: // "The 'ref' argument doesn't match the parameter type" } void Foo(A a) {} void Foo2(ref A a) {} } Why does the above compile-time error occur? This happens with both ref and out arguments. 回答1: ============= UPDATE: I used this answer as the basis for this blog entry: Why do ref and out parameters not allow type variation? See the blog page for more commentary on

Sybase IN and OUT parameters

↘锁芯ラ 提交于 2019-12-10 14:59:35
问题 I'm going nuts about how the Sybase JDBC driver handles stored procedures with mixed IN and OUT parameters. Check out this simple stored procedure: CREATE OR REPLACE PROCEDURE p (IN i1 INT, OUT o1 INT, IN i2 INT, OUT o2 INT) BEGIN set o1 = i1; set o2 = i2; END And here's how I'd call it with JDBC: CallableStatement c = connection.prepareCall("{ call dba.p(?, ?, ?, ?) }"); c.setInt(1, 1); c.setInt(3, 2); c.registerOutParameter(2, Types.INTEGER); c.registerOutParameter(4, Types.INTEGER); c

Why is the C# compiler claiming 'use of an unassigned variable' prior to 'yield return' and dynamic?

微笑、不失礼 提交于 2019-12-10 13:56:55
问题 The compiler complains that resultingThing in the code below is being used before being assigned to. private IEnumerable<IThing> FindThings(dynamic spec) { if (spec == null) yield break; IThing resultingThing; if (spec.Something > 0 && dictionary.TryGetValue(spec.Something, out resultingThing)) yield return resultingThing; else // ... } Why does it claim this? I have tried a different version of the method in which there are no yield usages (e.g. just return IEnumerable<IThing> ) but with the

How can i create out parameters with RAISERROR in stored procedure?

╄→尐↘猪︶ㄣ 提交于 2019-12-10 11:37:26
问题 How can i create out parameters with RAISERROR in MSSQL? This id stored procedure for example: BEGIN TRY //OPERATION END TRY BEGIN CATCH DECLARE @ErrorMessage NVARCHAR(4000); DECLARE @ErrorSeverity INT; DECLARE @ErrorState INT; SELECT @ErrorMessage = ERROR_MESSAGE(), @ErrorSeverity = ERROR_SEVERITY(), @ErrorState = ERROR_STATE(); -- Use RAISERROR inside the CATCH block to return error -- information about the original error that caused -- execution to jump to the CATCH block. RAISERROR (

Real-world examples where C# 'out' parameters are useful?

人盡茶涼 提交于 2019-12-08 23:12:38
问题 I'm reading up on core C# programming constructs and having a hard time wrapping my head around the out parameter modifier. I know what it does by reading but am trying to think of a scenerio when I would use it. Can someone give me a real-world example? Thanks. 回答1: there are many scenarios where you would use it, but the main one would be where your method needs to return more then one parameter. Take, for example, the TryParse methods on int type. In this case, instead of throwing an

C#: How to use generic method with “out” variable

半腔热情 提交于 2019-12-05 21:36:50
问题 I want to create a simple generic function void Assign<T>(out T result) { Type type = typeof(T); if (type.Name == "String") { // result = "hello"; } else if (type.Name == "Int32") { // result = 100; } else result = default(T); } Usage: int value; string text; Assign(value); // <<< should set value to 100 Assign(text); // <<< should set text to "hello" My question is how do you program the code to set these values ie. the missing codes in comment section. Thanks for any help. 回答1: It looks