I'm doing a personal project, I have two tables:
|---------|
|Area |
|---------|
|Cod_Area |
|Nomb_Area|
|Ubicacion|
|---------|
|---------|
|Empleados|
|---------|
|DNI |
|Nombre |
|Apellido |
|Cod_Area |
|Celular |
|Cargo |
|---------|
The latter is in a JFrame field Area
of my tblEmpleados
is a Combo Box , when I register an employee, in the Combo Box area I get the name of the area but I want you to save the area code in the BD and not the name, the name of the area only that appears when registering an employee in the JFrame .
I get this error
Conversion error when converting the nvarchar value 'Accounting' to data type int
This is the code to bring data from a support table to a Combo Box :
Statement Sent = cn.createStatement();
ResultSet rs = Sent.executeQuery("SELECT*FROM Area");
while(rs.next()){
this.ComboArea.addItem(rs.getString("Nomb_Area"));
This saves me data:
PreparedStatement pst = cn.prepareStatement("insert into Empleados values(?,?,?,?,?,?)");
pst.setString(1, txtDNI.getText().trim());
pst.setString(2, txtNombres.getText().trim());
pst.setString(3, txtApellidos.getText().trim());
pst.setString(4,ComboArea.getSelectedItem().toString());
pst.setString(5, txtCelular.getText().trim());
pst.setString(6, ComboCargo.getSelectedItem().toString());