Use of DatabaseColumns & DatabaseColumnName

Everything else that doesn't fall into one of the other PB categories.
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Use of DatabaseColumns & DatabaseColumnName

Post by fsw »

I've managed to connect to a SQL Server via ODBC and get the data from different tables without problems.

Pulling out the data was a little bit try & error because PB wants a Column number instead of a column name.

But using DatabaseColumns & DatabaseColumnName (to verify the number with the name) doesn't work.
The return value of DatabaseColumns is always 0...

Shouldn't I set the table first before using DatabaseColumns?
Didn't find a PB command for that.

Am I missing something?
Please bear with me, I'm a SQL novice :wink:

Thanks for any help.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

works well for me with MySQL

doing something like this :

Code: Select all

If DatabaseQuery(0,"SELECT * FROM mytable")
  nColumn = DatabaseColumns(0)
  While NextDatabaseRow(0)
    result$ = ""
    For i = 0 To nColumn - 1
      result$ + GetDatabaseString(0,i) + ", "
    Next i
    Debug result$
  Wend
EndIf
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

Thanks found my problem:
used them before doing a query...

Thanks again.
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post by Tranquil »

I use this Procedure to obtain the problem of column-numbers:

PB3.94 Code!

Code: Select all

Procedure GetDatabaseColumn(name$)
  For N=0 To DatabaseColumns()
    If DatabaseColumnName(N)=name$
      ProcedureReturn N
    EndIf
  Next N
  ProcedureReturn -1
EndProcedure 
Tranquil
Post Reply