Hello guys, I have a table that is supposed to store car information regarding license plate, model, brand and many other things. The problem is that I have another table called brand and in it has all the possible car brands that actually exists. On the table, it inserts the ID from the brand instead of the name. But when I want to show on the combobox ("License_plate - Brand - Model - Year_month") the brand is setting up to the ID instead of the name.
For example:
If i select the
Toyota
brand, the ID for that brand is 1. If so, the table will look something like this:
Data values inserted on `Cars` table
IDCAR: "1"
Brand: "1" -> Referred to TOYOTA on the table `Brands`
License_plate: "22-33-AD"
Model: "Yaris"
Year_month: "17/05"
Tables:
km_carro (referred to `Cars` in this topic)
CREATE TABLE `km_carro` (
`IDCARRO` int(11) NOT NULL AUTO_INCREMENT,
`MATRICULA` varchar(50) NOT NULL,
`ANO_MES` varchar(50) NOT NULL,
`MODELO` varchar(50) NOT NULL,
`MARCA` int(11) NOT NULL,
`OBS` text NOT NULL,
`COLABORADOR` varchar(250) DEFAULT NULL,
PRIMARY KEY (`IDCARRO`),
KEY `FK_MARCA` (`MARCA`),
KEY `FK_MODELO` (`MODELO`),
KEY `FK_COLABORADOR` (`COLABORADOR`),
CONSTRAINT `FK_MARCA` FOREIGN KEY (`MARCA`) REFERENCES `km_marca` (`IDMARCA`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8
km_marca ( referred as `Brands`)
CREATE TABLE `km_marca` (
`IDMARCA` int(11) NOT NULL AUTO_INCREMENT,
`NOME` varchar(250) DEFAULT NULL,
PRIMARY KEY (`IDMARCA`)
) ENGINE=InnoDB AUTO_INCREMENT=69 DEFAULT CHARSET=utf8
What I want:
Simply show the car data on a combobox regarding another form.
What I have tried:
Actually, I have written this code based on another project that is using ID-Name on the combobox and I've managed to sort it like I want, but instead of the Brand_name, it gives me the 'Brand_ID'
da.SelectCommand = New MySqlCommand("SELECT IDCAR, Concat(License_plate ,' - ', Brand, ' - ', Model, '-', Year_month) As 'CAR' from zestagio.cars ", con)
cmbCarro.DataSource = dt
cmbCarro.DisplayMember = "Carro"
cmbCarro.ValueMember = "IDCARRO"