Private Sub pesquisaNome(ByVal txtNome As TextBox)
reconect()
txtNome.AutoCompleteMode = AutoCompleteMode.Suggest
txtNome.AutoCompleteSource = AutoCompleteSource.CustomSource
strsql = "SELECT * FROM motorista WHERE motorista_nome LIKE '%" & txtNome.Text & "%'"
Dim objCommand As New MySqlCommand(strsql, conn)
dr_usuario = objCommand.ExecuteReader()
While (dr_usuario.Read())
txtNome.AutoCompleteCustomSource.Add(dr_usuario.Item("motorista_nome"))
End While
End Sub
I have three different search fields, one by Name, another by RG and another by CPF, and each one has a code exactly like this, changing only 3 arguments, where clause (driver_name, driver_rg etc ... ), the text of the TextBox control (txtNome.text "driver name", txtRG.text "rg number" etc. and the txtNome control, txtRG etc ..., I decided to create a function and pass through these values: / p>
Private Sub search(clausula As String, campo As String, controle As Object)
strsql = "SELECT * FROM motorista WHERE" & clausula & " LIKE '%" & campo & "%'"
Dim objCommand As New MySqlCommand(strsql, conn)
dr_usuario = objCommand.ExecuteReader()
While (dr_usuario.Read())
controle.AutoCompleteCustomSource.Add(dr_usuario.Item(campo))
End While
End Sub
and the passage would look something like this:
search("motorista_nome",txtnome,txtnome.text)
And my question is just how to pass the control by parameter, or if you have another way to join those searches in a code only ??
Thank you in advance!