I have a working Select query but since it contains multiple tables I can’t update it from my datagridview.
I’m sure it can be re-written to allow updates, but my SQL is quite limited.
SELECT d.Unique_Part_ID, d.Location_ID, d.Recorded_Value, d.Date_Time_Stamp, d.Traceability, d.Part_Status, d.Measure_State, p.Part_Number, p.Part_Rev, c.CN, c.Characteristic_Requirement, c.Characteristic_Name, c.Tol_min, c.Nominal_Value, c.Tol_Max, c.Proprietary_Tag FROM GE_KC_Data AS d INNER JOIN GE_Key_Characteristics AS c ON d.Characteristic_ID = c.ID INNER JOIN GE_Parts AS p ON c.PartID = p.ID WHERE IsNull(d.Reported,'False')='False' ORDER BY d.Date_Time_Stamp DESC
Any of you genius’s able to help? Using subquery statements also returns error “Only one expression can be specified in the select list when the subquery is not introduced with EXISTS” And of course I have no idea what that means.
Advertisement
Answer
I’m sure it can be re-written to allow updates
It can’t. Decide which table you will update and write an update statement for it and assign it to the updatecommand property of the dataadapter you’re using
If you will update two different tables, write a stored procedure to do the update, pass the data to the sproc (again, assigning it to the updatecommand of the dataadapter) and update multiple tables inside the sproc
Or loop the datatable that the datagridview is bound to, and commit updated rows yourself manually, using multiple update queries
For what it’s worth in situations like this where I have a master/slave data relationship to represent on a form, I don’t try to represent them in one grid, I use two, have a simple select for each table thereby having a dataset with updatable tables, I establish a datarelation between the two tables and then make the bindingsource of the slave grid have a datasource of (the master bindingsource) and a data property name of (the name of the dataset’s datarelation). This means when a master row is selected in the master grid, the slave grid filters to only rows pertinent to the selected master
You thus don’t end up with master cells repeated in a single grid (if you had orders and orderitems, then the orders data is repeated for every order item:
ordernum | customer name | item ordered 123 | John Smith | washer pump 123 | John Smith | door seal
If you edit the name of one row to Jane Smith, and the name on another row to John Jones, which row wins?
Having two grids and linked data is the proper way to do this. For more info see:
https://msdn.microsoft.com/en-us/library/fxsa23t6.aspx
Recommend you start by reading the “Creating a SImple Data Application” tutorial, regardless of how applicable the others might seem to your situation 😉