Row ID | Value |
1 | Item one |
2 | Item two |
3 | Item three |
4 | Item four |
Indexes in Listbox are changed, and row id in your database stays the same.
You can't use Listbox index for this purpose, row id must be stored somewhere else.
Why don't you use DBGrid to list your items?
Can't use DBGrid because I cannot get any database-aware components to work.
Does deleting a row not reorder the row IDs in the database? Because when I open the database in the DB browser, it appears that it does. Or if not automatically, is there an SQL command that will refresh the row IDs?
I mean selected by the user's mouse click in the DBGrid, not the Select command in SQL. :D
A ID in the DB is never changed. If you delete one row it is deleted and the other remains unchanged.Wrong.
Does deleting a row not reorder the row IDs in the database? Because when I open the database in the DB browser, it appears that it does.
Not more and not less - what should i discuss wit a DB-newbee about the theory of databaseprograming and the specialties of sqlite.A ID in the DB is never changed. If you delete one row it is deleted and the other remains unchanged.Wrong.
This only applies to surrogate Primary Keys (so called anonymous "ID"'s). And even then you can still change them
A primary Key can be anything as long as it is unique to the table resp. the data-model
My remarks are based on this lineAh, OK.Quote from: heebiejeebiesDoes deleting a row not reorder the row IDs in the database? Because when I open the database in the DB browser, it appears that it does.Not more and not less - what should i discuss wit a DB-newbee about the theory of databaseprograming and the specialties of sqlite.A ID in the DB is never changed. If you delete one row it is deleted and the other remains unchanged.Wrong.
This only applies to surrogate Primary Keys (so called anonymous "ID"'s). And even then you can still change them
A primary Key can be anything as long as it is unique to the table resp. the data-model
I know the problems of multi user Databasystems and replication for years (and i have learned to hate autoinc fields, they are so different between the platforms and a horror for replication).
How can the exact same code fail in one place and work in another?!
BTW: I think Zvoni can it better explain.Thank you for that vote of confidence :D
The only thing i can see is his Line 18 and Line 20/21 in the second code-block.
Line 18 would have expected:Line 20/21:
UserFileSave.Params.ParamByName('Newissuename').AsString:= NewIssueVar; //Notice the "AsString" instead of "Value"
You commit before you execute.
Turn it around: Execute first, then Commit
EDIT: This is just at first look.
There is other stuff, which is not making a lot of sense.
1) Why are you opening the connection (again)? Open it once at startup, and keep it open. Period.
2) Don't activate the Transaction if you don't need it
3) As a rule of thumb:
a) Let the User make all inputs
b) validate the input
c) (optional: Open the Connection) - Activate the Transaction
d) Set Parameters
e) Execute Insert/Update/Delete-Query
f) If not error, commit Transaction --> Hint: Lookup "Try... finally/except"
g) (Optional: Deactivate the Transaction)
1. Is there a way to get the DBGrid to scroll to the bottom and select the new entry?At a guess: DBGrid.DataSource.DataSet.Last
2. Speaking of scrolling, I have the ScrollBars property set to SSVertical. Doesn't work. Is there a way to get Scrollbars to actually appear on the DBGrid?Do you actually have enough entries to exceed the visible portion of the Grid?
3. Is there a way to fix the previous (MEMO) issue I had when using a DBLookupListBox ? I can get it to connect to the database no problem, so it seems to be a viable option, but all the data appears as (MEMO). There's no dgDisplaymemotext flag in the inspector like there is with DBGrid.And we're back at your SELECT * FROM .....
Thanks everyone!
At a guess: DBGrid.DataSource.DataSet.Last
Do you actually have enough entries to exceed the visible portion of the Grid?
And we're back at your SELECT * FROM .....
Try:
SELECT CAST(Field AS CHAR) AS Field, SomeOtherFields FROM MyTable
btw: Your "If ProtocolHomeTabs.ActivePage..."-Mess can be cut down
Const TableArray:Array[0..3] Of String=('NegPatterns','Custom1','Custom2','Custom3'); SQL:String='SELECT * FROM '; . . . ProtocolQuery.SQL.Text:=(SQL+TableArray[ProtocolHomeTabs.PageIndex]);
No reason to pollute the code with those If/Then
Haha, thank you! :) Maybe if I post enough of my horrible code I can get you to optimise my entire program for free, just through sheer irritation!2 € / line of Code... *gggg*
Yes, although I've tried both ssVertical and ssAutoVertical and neither works in any case. I presume ssVertical should show them whether there's enough entries or not.Eh, No!
Spoke too soon. DBLookupListBox doesn't have an "OnCellClick" event, and when I put my code in the regular OnClick event, it doesn't recognise which row the user has selected - it just does everything as though the user had selected the first row.
Anyone know how to make it recognise the row? Or anyone have any other ideas about fixing the DBGRid scrollbars? Thanks!