vb.net 数组边界不能出现在类型说明符中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13440557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:11:47  来源:igfitidea点击:

Array Bounds cannot appear in type specifier

vb.netwinforms

提问by Rara Arar

I keep having this error within a line of my code and I can't seem to fix it.

我一直在我的代码行中遇到这个错误,我似乎无法修复它。

Here is my code:

这是我的代码:

con.Open()
    Dim dt As DataTable
    Dim ds As DataSet
    ds.Tables.Add(dt)
    Dim da As OleDbDataAdapter

    da = New OleDbDataAdapter("Select From * product info", con)
    da.Fill(dt)

    Dim newRow As DataRow = dt.NewRow
    With newRow
        .Item("Product Name:") = txtItemName.Text
        .Item("Description") = txtDescription.Text
        .Item("Quantity:") = txtItemCount.Text
        .Item("Type:") = cmbItemType.Text
        .Item("Date Received:") = txtDate.Text
        .Item("Barcode:") = txtBarcode.Text
        .Item("Price:") = txtPrice.Text
    End With

    dt.Rows.Add(newRow)
    Dim cb As OleDbCommandBuilder(da)
    da.Update(dt)
    con.Close()

In the Dim cb As OleDbCommandBuilder(da)line I get the error on the da

在这一Dim cb As OleDbCommandBuilder(da)行中,我收到了错误da

回答by Steve

You have mixed the initialization and declaration of the variable cb.
The correct syntax to use is

您混合了变量cb的初始化和声明。
要使用的正确语法是

Dim cb As OleDbCommandBuilder = new OleDbCommandBuilder(da)

or

或者

Dim cb As OleDbCommandBuilder      'declaration
cb = new OleDbCommandBuilder(da)   'initialization

or (as explained by Konrad below)

或(如下面的康拉德所解释的)

Dim cb As New OleDbCommandBuilder(da)