Completely new to spider so this may already been answered.
How do i reference field names from a db query by name instead of using relative numbers.
instead of using DatabaseField(1, 1),, I would like to use something like DatabaseField(itemNum) .
Problem is if I change the db table the relative numbers would require me changing all programs that use that table.
Thanks for the help
relative field names from db
Re: relative field names from db
You can use DatabaseColumnIndex():
Code: Select all
ReturnValue.s = GetDatabaseString(YourDatabase, DatabaseColumnIndex(YourDatabase, "YourTableField"))
Re: relative field names from db
Being new to this, will this work.
Query$ = "SELECT * FROM items"
; Retrieve column names dynamically
For FieldIndex = 1 To DatabaseColumns(1)
Local FieldName$ = ColumnName(1, FieldIndex)
SendString("<th>" + FieldName$ + "</th>")
; Store field name and index in the mapping array
FieldIndexMap{FieldName$} = FieldIndex
Next
Then I should be able to retrieve the data as;
DatabaseField(1,"itemNum"}
DatabaseFoe;d(1,onHand"}
is this correct..
Thanks for the help
Query$ = "SELECT * FROM items"
; Retrieve column names dynamically
For FieldIndex = 1 To DatabaseColumns(1)
Local FieldName$ = ColumnName(1, FieldIndex)
SendString("<th>" + FieldName$ + "</th>")
; Store field name and index in the mapping array
FieldIndexMap{FieldName$} = FieldIndex
Next
Then I should be able to retrieve the data as;
DatabaseField(1,"itemNum"}
DatabaseFoe;d(1,onHand"}
is this correct..
Thanks for the help