本文介绍了请帮忙! ParameterValues作为列表(SqlParameter的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我使用下面的功能.使用此代码:

Hi All,
I use the function below. Using this code:

Dim Parameters(0 To 1) As SqlParameter
Parameters(0) = New SqlParameter("@username";, txtUsername.Text)
Parameters(1) = New SqlParameter"@ret", ret)
ret =clsDataAccess.NonQuery("usp_checkLogin",Parameters,
CommandType.StoredProcedure)


我在函数(ByVal ParameterValues As List(Of SqlParameter))中的第二个参数(Parameters)中遇到错误...错误是....
类型为"System.Data.SqlClient.SqlParameter的一维数组"的值不能转换为"System.Collections.Generic.List(System.Data.SqlClient.SqlParameter)". />
我的代码中缺少什么?

功能如下:


I got an error in the second parameter (Parameters) in the function (ByVal ParameterValues As List(Of SqlParameter)... the error is ....
Value of type ''1-dimensional array of System.Data.SqlClient.SqlParameter'' cannot be converted to ''System.Collections.Generic.List(Of System.Data.SqlClient.SqlParameter)''.

What''s missing in my code?

Here is the function:

Public Shared Function NonQuery(ByVal CommandText As String, _
           ByVal ParameterValues As List(Of SqlParameter), _
           ByVal CommandType As CommandType) As Integer
        Dim res As Integer = 0
        Dim Parameter As SqlParameter
        Dim SqlConn As SqlConnection = Connection
        Try
            SqlConn.Open()
            SqlComm = New SqlCommand(CommandText, SqlConn)
            SqlComm.CommandTimeout = 600
            SqlComm.CommandType = CommandType
            If (ParameterValues IsNot Nothing) Then
                For Each Parameter In ParameterValues
                    SqlComm.Parameters.Add(Parameter)
                Next
            End If
            res = SqlComm.ExecuteNonQuery()
        Catch ex As Exception
            Throw ex
        Finally
            SqlConn.Close()
        End Try
        Return res
    End Function</pre>


再次,请帮助我.

提前非常感谢!
问候,


Again, please help me..

Thanks so much in advance!
Regards,

推荐答案


"usp_checkLogin",Parameters.ToList,CommandType.StoredProcedure)



更好的解决方法:首先使用列表



Better Fix: Use a list in the first place

Dim Parameters As New List(Of SqlParameter)
Parameters.Add(New SqlParameter("@username", txtUsername.Text))
Parameters.Add(New SqlParameter("@ret", ret))


Parameters(1) = New SqlParameter"@ret", ret)



应该是这样的:



It should be this:

Parameters(1) = New SqlParameter("@ret", ret)


这篇关于请帮忙! ParameterValues作为列表(SqlParameter的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 11:00