vb.net 如何修复“参数过多”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28297226/
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 18:46:03  来源:igfitidea点击:

How to fix "Too many arguments"-error

vb.net

提问by emilkitua

im working on this point of sale system in vb and im stuck on an error

我正在用 vb 开发这个销售点系统,但我遇到了一个错误

Error 2 Too many arguments to 'Public Overridable Overloads Function Insert(ItemName As String, BuyPrice As Integer?, SellPrice As Integer?) As Integer'.

错误 2 “公共可覆盖重载函数插入(项目名称为字符串,BuyPrice 为整数?,SellPrice 为整数?)为整数”的参数过多。

how can i clear it?

我怎样才能清除它?

the double stared **is where the error is

双目注视**是错误所在

my code: add item window

我的代码:添加项目窗口

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

   Public Class AddItem

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Me.DialogResult = Windows.Forms.DialogResult.Cancel
End Sub

'used to insert the item

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    'perform validation for barcode
    If TextBox1.Text.Trim = "" Then
        MsgBox("You should enter a barcode number", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox1.Focus()
        Exit Sub

    End If

    If Not IsNumeric(TextBox1.Text) Then
        MsgBox("You should enter a numeric barcode number", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox1.Focus()
        Exit Sub
    End If

    If TextBox1.Text.Contains(".") Or TextBox1.Text.Contains("-") Then
        MsgBox("The barcode number should not contain special characters", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox1.Focus()
        Exit Sub
    End If

    'perform check for the item name
    If TextBox2.Text.Trim = "" Then
        MsgBox("You should enter a name for the item", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox2.Focus()
        Exit Sub

    End If

    'perform a check for the buy price
    If TextBox3.Text.Trim = "" Then
        MsgBox("You should enter the buying price", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox3.Focus()
        Exit Sub

    End If

    If Not IsNumeric(TextBox3.Text) Then
        MsgBox("You should enter a numeric buying price", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox3.Focus()
        Exit Sub
    End If

    Dim BuyPrice As Decimal = Decimal.Parse(TextBox3.Text)
    If BuyPrice < 0 Then
        MsgBox("The buying price cannot be negative", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox3.Focus()
        Exit Sub
    End If

    'perform a check for the selling price
    If TextBox4.Text.Trim = "" Then
        MsgBox("You should enter the selling price", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox4.Focus()
        Exit Sub

    End If

    If Not IsNumeric(TextBox4.Text) Then
        MsgBox("You should enter a numeric selling price", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox4.Focus()
        Exit Sub
    End If

    Dim SellPrice As Decimal = Decimal.Parse(TextBox4.Text)
    If SellPrice < 0 Then
        MsgBox("The selling price cannot be negative", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox4.Focus()
        Exit Sub
    End If

    If SellPrice <= BuyPrice Then
        MsgBox("The selling price cannot be less than buying price", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox4.Focus()
        Exit Sub
    End If

    'perform check for quantity
    'If Not IsNumeric(TextBox5.Text) Then
    'MsgBox("You should enter a numeric digits", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
    'TextBox5.Focus()
    'Exit Sub
    'End If

    'Dim Quantity As Decimal = Decimal.Parse(TextBox5.Text)
    'If Quantity < 0 Then
    'MsgBox("Quantity cant be negative", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
    ' TextBox5.Focus()
    'Exit Sub
    'End If


    'insert the item

    Try
        'create the adapter
        Dim TA As New POSDSTableAdapters.ItemsTableAdapter

        'insert the item
        'TA.Insert(TextBox1.Text, TextBox2.Text, BuyPrice, SellPrice, Quantity)
        TA.Insert(TextBox2.Text, BuyPrice, SellPrice)


        Me.DialogResult = Windows.Forms.DialogResult.OK

    Catch ex As Exception

        'display error message
        'handle error
        MsgBox(ex.Message, MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)

    End Try
End Sub

Private Sub AddItem_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub

End Class

结束班

main window code: Public Class MainWindow

主窗口代码:公共类 MainWindow

Private Sub MainWindow_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'MyDataset.Items' table. You can move, or remove it, as needed.
    Me.ItemsTA.Fill(Me.MyDataset.Items)

    Try


    'get the username from the user
        'Dim USRWin As New PasswordPicker

    'get the password from the user
        ' Dim PSWWin As New PasswordPicker


    'if the user hits the exit button then stop executing the program
        'If PSWWin.ShowDialog <> Windows.Forms.DialogResult.OK Then

        'End

        ' End If

        'get the usernme
        'Dim USR As String = USRWin.TextBox1.text
        'get the password
        'Dim PSW As String = PSWWin.TextBox2.text


        'get the password from the database
        ' Dim TA As New POSDSTableAdapters.ValuesTableAdapter
        'Dim TB = TA.GetDataByKey("password")
        ' Dim DBPSW As String = TB.Rows(0).Item(1)

        'check the passwords match
        ' If PSW <> DBPSW Then
        'MsgBox("Invalid password", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        ' End If

        'get the username
        ' Dim TK = TA.GetDataByKey("username")
        'Dim DBUSR As String = TK.Rows(0).Item(2)

        'check the username match
        'If USR <> DBUSR Then
        'MsgBox("Invalid username", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        'End If

        'load the items info from db into the dataset
        ItemsTA.Fill(MyDataset.Items)


    Catch ex As Exception

        'handle error
        MsgBox(ex.Message, MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)

    End Try
End Sub

Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs)

End Sub

'add item to the db
Private Sub AddItemToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AddItemToolStripMenuItem.Click
    Dim AddItemWindow As New AddItem
    If AddItemWindow.ShowDialog = Windows.Forms.DialogResult.OK Then
        'load the info of items from db
        ItemsTA.Fill(MyDataset.Items)
    End If


End Sub

'used to select an item
Private Sub EditItemToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles EditItemToolStripMenuItem.Click

    'make sure an item is selected
    If DataGridView1.SelectedRows.Count = 0 Then
        Exit Sub
    End If

    'get the barcode of the item
    Dim Barcode = DataGridView1.SelectedRows(0).Cells(0).Value

    'create the edit window
    Dim EditItemWindow As New EditItem

    'fill the window with information
    EditItemWindow.FillItemInfo(Barcode)

    If EditItemWindow.ShowDialog = Windows.Forms.DialogResult.OK Then
        'load the info of items from db
        ItemsTA.Fill(MyDataset.Items)
    End If
End Sub

End Class

结束班

回答by Tim Schmelter

Isn't the error-message self-explanatory?

错误消息不是不言自明的吗?

Too many arguments to 'Public Overridable Overloads Function Insert(ItemName As String, BuyPrice As Integer?, SellPrice As Integer?) As Integer'

“公共可覆盖重载函数插入(项目名称为字符串,BuyPrice 为整数?,SellPrice 为整数?)为整数”的参数太多

You are passing four arguments at:

您正在传递四个参数:

 TA.Insert(TextBox1.Text, TextBox2.Text, BuyPrice, SellPrice)

Maybe you want:

也许你想要:

TA.Insert(TextBox1.Text, BuyPrice, SellPrice)