0

我想使用 SQl 参数数组。当我在网上搜索时,我在下面的链接中得到了非常有用的数据。VB.Net .VS2005 中的 sqlParameters 数组在 NEW 附近显示语法错误。

代码如下

Dim parameters() As SqlParameter = New SqlParameter() _
    {
      New SqlParameter("@first_name", SqlDbType.VarChar, 50) With { .Value = "john"},
      New SqlParameter("@last_name", SqlDbType.VarChar, 50) With { .Value = "doe"},
      New SqlParameter("@age", SqlDbType.Int) With { .Value = 18},
      New SqlParameter("@id", SqlDbType.Int) With { .Value = 123}
    }
4

1 回答 1

1

Your code uses object initializers which where introduced in VB.Net 9.0 (Visual Studio 2008); hence you can't use them in VB.Net 8.0 (Visual Studio 2005).

You have to do it the verbose way, e.g.:

Dim parameters(3) As SqlParameter

Dim p As SqlParameter
p = New SqlParameter("@first_name", SqlDbType.VarChar, 50)
p.Value = "john"
parmaters(0) = p

p = New SqlParameter("@last_name", SqlDbType.VarChar, 50)
p.Value = "doe"
parmaters(1) = p

...
于 2013-09-18T10:36:38.993 回答