I’m writing a front end to a database, presenting options as comboboxes. And I need to be able to return nulls to the database.
I have a solution at the moment which involves ‘fudging’ a record into the query to populate the Datatable, then detecting the selection and hard coding null into my update statement if this item has been selected.
--GetDataByAvailableTechs query SELECT tblLEMSCredentialsId, TechNumber FROM tblLEMSCredentials AS aLEMSCreds UNION ALL SELECT '99999' AS Expr1, '<NONE>' AS Expr2
.
//populate combo box BV_LEMSHIPDataSet.tblLEMSCredentialsDataTable dtAvailableTechs = taLEMSCreds.GetDataByAvailableTechs(selectedSerial); cboTechNumber.DataSource = dtAvailableTechs;
.
//Save back to DB if (lemsCredsID == 99999) { taDevice.UpdateQuery_Restage(null, selectedSerial); } else { taDevice.UpdateQuery_Restage(lemsCredsID, selectedSerial); }
Can anyone suggest a better way of doing this please? I need to make the application cope with another 5 similar fields and don’t want to create a multitude of if else versions of my update.
G
In the past I’ve used a similar approach but used minus numbers for the NULL values – that way you can you treat anything less than zero as NULL in one if statement.
This assumes that your ID’s in the table are always positive though 🙂