Tuesday, 15 April 2014

.net - Is there any way to reduce this ado.net code? -


I need to reduce this code a lot, any way to create a SQL parameter to describe its direction is?

  dim Oparam1 As SqlParameter = new SqlParameter ( "@ Rojo", SqlDbType.Int) dim Oparam2 As SqlParameter = new SqlParameter ( "@ Amber", SqlDbType.Int) dim: Here is the code Oprm 3 as SqlParameter = "new Zealand", "Smeldibi type. Aianti" DM Oprm 4 Skyuelpirametik as = new Sclpirametr ( "@ Verde", Ssieldibi type. Aianti) Opram 1. DIRECTIONS = PARAMETER DIRECTION. OPTUP OPERUM 2 Direction = parameter Dayrekshnkoptput Oprm 3. Direction = ParameterDirection.Output Oparam4.Direction = ParameterDirection.Output command.Parameters.Add (Oparam1) command.Parameters.Add (Oparam2) command.Parameters.Add (Oparam3) command.Parameters.Add (Oparam4)   

Thanks in advance.

is one, but then you have many other parameters, then the code is not less then after all

You can create an extension method:.

  Import System.Runtime.CompilerServices module SqlExtensions & LT; Extension () & gt; Public function SetOutput (parameters as the SqlParameter) SqlParameter parameter.Direction = ParameterDirection.Output Return parameter End Function End Module   

You can now use the standards-based:

  command.Parameters.Add (new SqlParameter ( "@ Rojo", SqlDbType.Int) .SetOutput ()) command.Parameters.Add (new SqlParameter ( "@ Amber", SqlDbType.Int ) .SetOutput ()) command .Parameters.Add (new SqlParameter ( "@ AMARILLO", SqlDbType.Int) .SetOutput ()) command.Parameters.Add (new SqlParameter ( "@ Verde", SqlDbType.Int) .SetOutput ( ))    

No comments:

Post a Comment