asp.net - TVP - Failed to convert parameter value from a SqlParameter to a IEnumerable`1 -


I am trying to create a general purpose function that can accept TVP.

I'm getting the error 'Failed to change the parameter value from an SqlParameter to an IEnumerable`1.' Param.SqlDbType = SqlDbType.Structured sqlProvider.ExecuteNonQueryV2 ("sp_Save", CommandType: StringProver, Ultimate) - The Ultimate New SqlParameter ("@ ParName", as GetTVP). -------------------- Public Function ExecuteNonQuery (ByVal as string, ByRef returnValue as integer, byVal ParamArray parameterValues ​​() as an object) Integer SqlConnection = SqlTransaction as some low transaction in the form of slow connection as SqlCommand = nothing as command = R0 = 1 SqlConnection as nothing MyconnectionString command = new SQL command (spname, connection) command.CommandType = CommandType.StoredProcedure connection.Open () SqlCommandBuilder.DeriveParameters (command) Me.SetParameters (command, parameterValues) transaction = connection.BeginTransaction () command.Transaction = transaction R = Command.ExecuteNonQuery () Hold as transaction.Commit (E) Justification End and Return R & R Function --------------------- Private All Set Parameters (SVL Commands, By Value Parameters Values ​​(in the form of Objects) are param SqlParameter in cmd.Parameters param.Value = parameterValues ​​(i) i + = 1 Next End Sub

h Dr.

I have updated the code and carry out "SqlCommandBuilder.DeriveParameters (command)" and passed parameter as a sqlparameter list. All work is fine now :)

But I would love to know why this is working when I did not configure the parameter type SqlDbType. it's not necessary?

  Dim the parallel new list par.Add (New SqlParameter (SqlParameter) (as "@ parName", GetTVP (lstDates)) ---- ----------- Connection = New SqlConnection (myconnectionString) command = New SqlCommand (spname, connection) command.CommandType = CommandType.StoredProcedure connection.Open () Me.SetParameters (command, parameterValues) Transactions = connection.BeginTransaction () command.Transaction = Transactions r = command.ExecuteNonQuery () transaction.Commit ()    

Why did you not pass a list of SqlParameter in a list of items as a parameter in the signature,

In this way;

  Public Function ExecuteNonQuery (ByVal spname string, ByRef returnValue as integer, as the parameter list (SqlParameter's) byRef as integer)   

Then you can loop and add

  in the SqlParameter parameter command for each paragraph. Parameter. Add (Para) Next   

Check this link out exclusively and it is recommended that you define the parameter type, although it is not mandatory.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -