Hello All,
I know this is a common topic, I search into topics and google to find a solution, but I cant find.
I need to search into datagridview by one field which is not a primary key.
The code below works fine for me in another windows form. But I have to use it in another windows form to search by name instead by "Cod_cliente", if I rename "Cod_cliente" into "nombre" it does not work, showing the error "No value given for one or more required parameters."
The tables is:
CLIENTE(Cod_cliente,nombre,apellido,direccion,telefono,email)
Anyone can tell me why does not work with another column?
I know this is a common topic, I search into topics and google to find a solution, but I cant find.
I need to search into datagridview by one field which is not a primary key.
The code below works fine for me in another windows form. But I have to use it in another windows form to search by name instead by "Cod_cliente", if I rename "Cod_cliente" into "nombre" it does not work, showing the error "No value given for one or more required parameters."
The tables is:
CLIENTE(Cod_cliente,nombre,apellido,direccion,telefono,email)
Code:
Private Sub Buscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buscar.Click
If Not Conex.State = ConnectionState.Open Then
Conex.Open()
End If
Dim consulta As String
Dim lista As Byte
Try
If TXTBusqueda.Text <> "" Then
consulta = "Select * from CLIENTE where Cod_cliente=" & TXTBusqueda.Text
adap = New OleDbDataAdapter(consulta, Conex)
dset = New DataSet
adap.Fill(dset, "Cod_cliente")
lista = dset.Tables("Cod_cliente").Rows.Count
Else
MessageBox.Show("Ha de escribir un codigo", "Advertencia", MessageBoxButtons.OK)
End If
Catch ex As Exception
MessageBox.Show("El codigo de cliente no existe", "Advertencia", MessageBoxButtons.OK)
End Try
If lista <> 0 Then
DataGridView1.DataSource = dset
DataGridView1.DataMember = "Cod_cliente"
End If
Conex.Close()
End Sub