从 C# 中初始化 VB.Net 中的 SQLParameter 数组的语法是什么

发布于 2024-12-02 17:46:00 字数 606 浏览 3 评论 0原文

我已经很久没有接触VB了,所以我需要一些帮助。我的 C# 代码中有以下内容

SqlParameter[] param = new SqlParameter[0];
 ...some code...
param = new SqlParameter[2];
param[0] = db.MakeInputParameter("@group_id", groupid);
param[1] = db.MakeInputParameter("@organization_id", orgid);

我不首先初始化大小的原因是因为我在同一方法中重用了 param 变量,以防万一您想知道

以下是我尝试过的,但我不断得到该变量是在赋值之前使用

Dim param() As SqlParameter
...some code...
param(2) = New SqlParameter
param(0) = db.MakeInputParameter("@group_id", groupid)
param(1) = db.MakeInputParameter("@organization_id", orgid)

如何将这种类型的逻辑转换为 VB.Net

It has been way to long since I have been involved in VB so I need some help here. I have the following in my C# code

SqlParameter[] param = new SqlParameter[0];
 ...some code...
param = new SqlParameter[2];
param[0] = db.MakeInputParameter("@group_id", groupid);
param[1] = db.MakeInputParameter("@organization_id", orgid);

The reason i do not initialize the size firstly is because i reuse the param variable in the same method, just in case you were wondering

The following is what I have tried but I keep getting that the variable is used before I assign a value

Dim param() As SqlParameter
...some code...
param(2) = New SqlParameter
param(0) = db.MakeInputParameter("@group_id", groupid)
param(1) = db.MakeInputParameter("@organization_id", orgid)

How do I convert this type of logic to VB.Net

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无声无音无过去 2024-12-09 17:46:00

使用 ReDim

Dim param() As SqlParameter
Redim param(1) 'The value VB.NET array subscript uses upper-bound.

或者

param = New SqlParameter(1) {}

Use ReDim

Dim param() As SqlParameter
Redim param(1) 'The value VB.NET array subscript uses upper-bound.

Or

param = New SqlParameter(1) {}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文