Hola,
os cuento:
quiero hacer que un combo que yo relleno con los nombre de un cliente de la tabla tbl_clientes me devuelva el idcliente de la tabla tbl_pagosdevoluciones, los campos son:
Esta todo en clases, ClsDatosClientes,ClsPagosDevoluciones y el formulario FrmPagosDevoluciones, despues en otra clase tengo la conexion (ClsBaseAccess)
tbl_clientes:
Idcliente,nombre,apellidos,direccion,provincia,ciudad,telef ono,cp(codigopostal)
tbl_pagosdevoluciones: IdPagos,Importe,
Idcliente,Descripcion,fecha
Los campos idcliente esta relacionados en la base acces.
El combo lo cargo de esta manera:
Código vb:
Ver originalPublic Function CargarComboClientes() As OleDb.OleDbDataAdapter
Dim CCargar As New OleDb.OleDbDataAdapter("Select * from tbl_clientes order by nombre", _cnClientes)
Return CCargar
End Function
Private Sub FrmPagosDevoluciones_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dst As New DataSet
Dim ds As New ClsDatosClientes
Dim cc As New ClsPagosDevoluciones
Dim dt As New DataTable
dst = ds.CargarTablaPagos
Grid1.DataSource = dst.Tables(0)
cc.CargarComboClientes.Fill(dt)
CbCliente.DataSource = dt
CbCliente.DisplayMember = "Nombre"
CbCliente.ValueMember = "IdCliente"
CbCliente.Text = ""
End Sub
Y ahora para agregar los registros:
Código vb:
Ver originalPublic Function GuardarPagos(ByVal Pagos As ClsPagosDevoluciones) As String
Dim CGuardar As New OleDb.OleDbCommand
CGuardar.Connection = _cnClientes
CGuardar.CommandText = "Insert into tbl_pagosdevoluciones(Importe,IdCliente,Descripcio n, fecha)" & _
"values " & _
"(@importe,@idcliente,@descripcion,@fecha)"
CGuardar.Parameters.AddWithValue("@importe", Pagos.Importe)
CGuardar.Parameters.AddWithValue("@Idcliente", Pagos.IdCliente)
CGuardar.Parameters.AddWithValue("@Descripcion", Pagos.Descripcion)
CGuardar.Parameters.AddWithValue("@fecha", Pagos.Fecha)
_cnClientes.Open()
Dim t As Integer = CInt(CGuardar.ExecuteScalar())
_cnClientes.Close()
Return t
End Function
Public Sub GuardarCampos()
Dim ds As New ClsDatosClientes
ds.GuardarPagos(Me)
End Sub
Private Sub btnAgregarReg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAgregarReg.Click
Dim ds As New ClsDatosClientes
Dim CGuardar As New ClsPagosDevoluciones
Try
If MsgBox("¿Desea guardar los datos?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
CGuardar.Importe = txtImporte.Text
CGuardar.IdCliente = CbCliente.Text
CGuardar.Descripcion = txtDescripcion.Text
CGuardar.Fecha = DTFecha.Text
CGuardar.GuardarCampos()
Grid1.DataSource = ds.CargarTablaPagos.Tables(0)
End If
Catch ex As Exception
MsgBox("Error:" & ex.Message)
End Try
End Sub
Cuando le doy al boton agregar me salta un error en la funcion GuardarPagos:
Dim t As Integer = CInt(CGuardar.ExecuteScalar()) no coinciden los datos en la expresion de criterios.
Espero que me hayan entendido y me puedan ayudar.
Gracias y Saludos