VB - Too Many Arguments

Asked

Viewed 47 times

-1

Good, I have the following mistake:

Error: Too many arguments to 'Friend Sub LerClientes1()'.   

In the following code:

 Imports MySql.Data.MySqlClient 'importar as classes do MySQL

Imports MySql.Data.MySqlClient.MySqlConnection 'importar as classes do MySQL

Public Class Clientes

    Dim conn As MySqlConnection 'definir a variável conn como uma instância do MySQLConnection
    Public user As String 'define uma variável nome do tipo pública de modo a que possa navegar entre as diferentes forms da aplicação sem perder a autenticação
Public pass As String
Private myConnString As String
Dim myCommand As New MySqlCommand
Dim myAdapter As New MySqlDataAdapter
Dim myData As New DataTable
Dim SQL As String
Dim dbDataSet As DataSet
Dim idCliente As Integer

Friend Sub LerClientes()
    Dim conn As New MySqlConnection
    Dim myCommand As New MySqlCommand
    Dim myAdapter As New MySqlDataAdapter
    Dim myData As New DataTable
    Dim SQL As String
    SQL = "SELECT * from Clientes"
    Dim myConnString As String
    myConnString = "server=localhost;user id=root;database=Empresa"
    conn.ConnectionString = myConnString
    Try
        conn.Open()
        Try
            DataGridClientsDesign()
            myCommand.Connection = conn
            myCommand.CommandText = SQL
            myAdapter.SelectCommand = myCommand
            dbDataSet = New DataSet
            myAdapter.Fill(dbDataSet, "Clientes")
            procurar1.tabelaprocurar.DataSource = dbDataSet
        Catch myerror As MySqlException
            MsgBox("Houve um erro de leitura na base de dados: " & myerror.Message)
        End Try
    Catch myerror As MySqlException
        MessageBox.Show("Erro na ligação à base de dados: " & myerror.Message)
    Finally
        If conn.State <> ConnectionState.Closed Then conn.Close()
    End Try
End Sub

Friend Sub LerClientes1()
    Dim conn As New MySqlConnection
    Dim myCommand As New MySqlCommand
    Dim myAdapter As New MySqlDataAdapter
    Dim myData As New DataTable
    Dim SQL As String
    SQL = "SELECT * from ClientesEmp"
    Dim myConnString As String
    myConnString = "server=localhost;user id=root;database=Empresa"
    conn.ConnectionString = myConnString
    Try
        conn.Open()
        Try
            DataGridClientsDesign()
            myCommand.Connection = conn
            myCommand.CommandText = SQL
            myAdapter.SelectCommand = myCommand
            dbDataSet = New DataSet
            myAdapter.Fill(dbDataSet, "ClientesEmp")
            Me.DataGridView1.DataSource = dbDataSet
        Catch myerror As MySqlException
            MsgBox("Houve um erro de leitura na base de dados: " & myerror.Message)
        End Try
    Catch myerror As MySqlException
        MessageBox.Show("Erro na ligação à base de dados: " & myerror.Message)
    Finally
        If conn.State <> ConnectionState.Closed Then conn.Close()
    End Try
End Sub

Private Sub TabPage4_Click(sender As Object, e As EventArgs)

End Sub

Private Sub Button9_Click(sender As Object, e As EventArgs)

End Sub

Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles GroupBox1.Enter

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim strSQL As String
    strSQL = "INSERT INTO Clientes(NIF, Nome, Morada, CPostal, Localidade, Telefone, Fax, Email, Volume, Sector, FormJuri) VALUES (?NIF, ?Nome, ?Morada, ?CPostal, ?Localidade, ?Telefone, ?Fax, ?Email, ?Volume, ?Sector, ?FormJuri)"
    Dim oCmd As New MySqlCommand(strSQL, conn)
    oCmd.Parameters.Add(New MySqlParameter("NIF", nif.Text))
    oCmd.Parameters.Add(New MySqlParameter("Nome", txtnome.Text))
    oCmd.Parameters.Add(New MySqlParameter("Morada", txtmorada.Text))
    oCmd.Parameters.Add(New MySqlParameter("CPostal", txtcp.Text))
    oCmd.Parameters.Add(New MySqlParameter("Localidade", txtlocalidade.Text))
    oCmd.Parameters.Add(New MySqlParameter("Telefone", txttelefone.Text))
    oCmd.Parameters.Add(New MySqlParameter("Email", txtemail.Text))
    oCmd.Parameters.Add(New MySqlParameter("Sector", sectortxt.Text))
    oCmd.Parameters.Add(New MySqlParameter("Volume", volumetxt.Text))
    oCmd.Parameters.Add(New MySqlParameter("Fax", faxtxt.Text))
    oCmd.Parameters.Add(New MySqlParameter("FormJuri", formjuritxt.Text))
    MessageBox.Show("Dados introduzidos com sucesso!!", "Informacao")
    Try
        conn.Open()
        oCmd.ExecuteNonQuery()
    Catch exc As Exception
        MsgBox("Erro: " & exc.Source & " - " & exc.Message)
    Finally
        If (Not conn Is Nothing) AndAlso (conn.State = ConnectionState.Open) Then
            conn.Close()
        End If
    End Try
    nif.Text = ""
    txtnome.Text = ""
    txtmorada.Text = ""
    txtcp.Text = ""
    txtlocalidade.Text = ""
    txttelefone.Text = ""
    txtemail.Text = ""
    sectortxt.Text = ""
    formjuritxt.Text = ""
    faxtxt.Text = ""
    volumetxt.Text = ""
End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
    Dim openFileDialog2 As New OpenFileDialog()
    openFileDialog2.Title = "Please Select a Image"
    openFileDialog2.InitialDirectory = "C:"

    If openFileDialog2.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
        ' Assign the cursor in the Stream to the Form's Cursor property.  
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
        PictureBox1.Image = Image.FromFile(openFileDialog2.FileName)
        TextBox1.Hide()
    End If
End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
    PictureBox1.Image = Nothing
    TextBox1.Show()
End Sub

Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
    procurar111.Show()
End Sub

Private Sub procurarcombo_SelectedIndexChanged(sender As Object, e As EventArgs) Handles procurarcombo.SelectedIndexChanged

End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    nif.Text = ""
    txtnome.Text = ""
    txtmorada.Text = ""
    txtcp.Text = ""
    txtlocalidade.Text = ""
    txttelefone.Text = ""
    txtemail.Text = ""
    sectortxt.Text = ""
    formjuritxt.Text = ""
    faxtxt.Text = ""
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    Me.Hide()
    Form3.Show()
End Sub

Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    If nif.Text = "" Then
        MsgBox("Nao seleccionou nenhum cliente!")
        Exit Sub
    ElseIf MessageBox.Show("Tem a certea que pretende apagar?", "Atencao!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) * Windows.Forms.DialogResult.Yes Then
        Dim strSQL As String
        strSQL = "DELETE FROM Clientes WHERE NIF =" & nif.Text
        Dim myConnString As String
        myConnString = "server=localhost;user id=root;database=Empresa"
        conn.ConnectionString = myConnString
        Try
            Dim oCmd As New MySqlCommand(strSQL, conn)
            conn.Open()
            oCmd.ExecuteNonQuery()
            nif.Text = ""
            txtnome.Text = ""
            txtmorada.Text = ""
            txtcp.Text = ""
            txtlocalidade.Text = ""
            txttelefone.Text = ""
            txtemail.Text = ""
            sectortxt.Text = ""
            formjuritxt.Text = ""
            faxtxt.Text = ""
            LerClientes()
            Me.WindowState = FormWindowState.Normal
            Me.Show()
            MessageBox.Show("Dados apagados com Sucesso!", "Informacao!")
        Catch exc As Exception
            MsgBox("Erro: " & exc.Source & " - " & exc.Message & System.Environment.NewLine & exc.ToString)
        Finally
            If (Not conn Is Nothing) AndAlso (conn.State = ConnectionState.Open) Then
                conn.Close()
            End If
        End Try
    End If
End Sub

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
    procurar1.Show()
End Sub

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

    conn = New MySqlConnection()
    conn.ConnectionString = "server=localhost;user id=root;database=Empresa"
    Try
        conn.Open()
        conn.Close()
    Catch myerror As MySqlException
        MessageBox.Show("Erro na ligação à base de dados: " & myerror.Message)
        End
    Finally
        conn.Dispose()
    End Try
    TabPage1.Text = "Inf. Gerais"
    TabPage2.Text = "Inf. Internas"


End Sub

Private Sub TabPage2_Click(sender As Object, e As EventArgs) Handles TabPage2.Click

End Sub


Private Sub DataGridClientsDesign() 'Procedimento que contem o novo estilo da datagrid
    Me.DataGridView1.DataMember = "ClientesEmp" 'Nome da tabela associada no datagrid
    Me.DataGridView1.ReadOnly = True 'Coloca o datagrid apenas para leitura
    Dim GridStyle As New DataGridTableStyle 'Cria um novo estilo do datagrid
    GridStyle.MappingName = "ClientesEmp" 'Associa a relacao da tabela clientes com a da base de dados
    Dim CargoCol As New DataGridTextBoxColumn 'define a variavel do tipo DataGridTextBoxColumn
    CargoCol.MappingName = "Cargo" 'atribui um campo da tabela
    CargoCol.HeaderText = "Cargo" 'atribui um nome à coluna
    CargoCol.Width = 110 'define tamanho coluna
    GridStyle.GridColumnStyles.Add(CargoCol) 'adiciona coluna
    Dim nomeCol As New DataGridTextBoxColumn
    nomeCol.MappingName = "nome"
    nomeCol.HeaderText = "Nome"
    nomeCol.Width = 110
    GridStyle.GridColumnStyles.Add(nomeCol)
End Sub

Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
    Dim o As Integer
    If String.IsNullOrEmpty(o) = False Then
        Dim CM As CurrencyManager 'Cria um visualizador para a datagrid
        If IsNothing(dbDataSet) Or dbDataSet.Tables("ClientesEmp").Rows.Count = 0 Then Exit Sub 'Se a tabela nao conter nada o procedimento fecha
        CM = CType(BindingContext(dbDataSet, "ClientesEmp"), CurrencyManager) 'Associa ao visualizador a tabela Clientes que esta presente no dataset
        Dim DataRowV As DataRowView = CType(CM.Current, DataRowView) 'Cria uma nova Row que vai conter a linha que esta seleccionada no datagrid com o cliente
        idCliente = CType(DataRowV.Item("Nome"), Integer) 'Atribui o ID desse cliente
        Dim dbDataCliente As DataSet = LerClientes1(idCliente) 'Cria um dataset novo com a informaçao associada daquela Row
        procurar111.cargotxt.Text = dbDataCliente.Tables("ClientesEmp").Rows(o).Item("Cargo").ToString
        procurar111.txtnome.Text = dbDataCliente.Tables("ClientesEmp").Rows(o).Item("Nome").ToString
    Else
        MsgBox("Erro: Este cliente não existe!")
    End If
End Sub


End Class

The intended is to add data to a table from another form linked to the database.

Data is added to the database, but with this error is not shown in the table.

I would appreciate your help as soon as possible.

Thank you.

  • At what point is the error occurring? No build? Which version of Visual Studio are you using?

1 answer

1


You’re calling the function by passing idCliente

Lerclients1(idCliente)

But its function has no parameters.

Friend Sub Lerclientes1()

You can change to:

Friend Sub LerClientes1(int IdCLiente)

and changes your query to:

"SELECT * from ClientesEmp where idCleinte= " + idcliente.

Or leave as is and in the call of your sub, You take the parameter idcliente.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.