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

时间:2012-11-18 13:27:33

标签: vb.net winforms

我一直在我的代码行中出现此错误,我似乎无法修复它。

这是我的代码:

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()

Dim cb As OleDbCommandBuilder(da)行中,我在da

上收到错误消息

1 个答案:

答案 0 :(得分:4)

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

Dim cb As OleDbCommandBuilder = new OleDbCommandBuilder(da)

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

或(如下面Konrad所解释的)

Dim cb As New OleDbCommandBuilder(da)