Thanks for the help, but I must caution some of you... you were
close but not right. I had asked how I get a list of tables into
MapBasic variables after opening an SQL Server database. Everyone
who sent me a suggestion had the general idea, which was to use
Server_Execute to pass an SQL string like 
"Select cast(name as varchar(100)) From sysobjects where xtype =
'U'"

You need to cast 'name' like that because by default it's 384
characters and is too long for a mapbasic variable. But this
select doesn't get the list of table names into mapbasic. (and
"select * ..." won't work either.

Cindy from MapInfo Tech Support gave me the full answer, and it
works almost perfectly. The "order by" clause below has a bug; it
causes the first table to be missing in the select. So leave that
out. I'd also increase the size of the table name variables. But
here's the code:

dim hstmt As Integer
dim queryStr as string
dim demohdbc as integer
dim numrec as integer
dim i as integer
dim tabname as string
dim tabar(10) as string
dim tabstat,numstat as integer

demohdbc = SERVER_CONNECT("QELIB","dsn=bugs;uid=ts;pwd=ts;")

hstmt = server_execute(demohdbc,
  "select count(*) from sysobjects where xtype='U'")
server hstmt bind column 1 to numrec,numstat

server hstmt fetch first
redim tabar(numrec)

hstmt = server_execute(demohdbc,
"select cast(name as char(20))from sysobjects "
   + "where xtype='U' order by name")

server hstmt fetch first
server hstmt bind column 1 to tabname,tabstat
i=1
   while not server_eot(hstmt)
      tabar(i)= tabname
      i=i+1
      server hstmt fetch next
   wend
server hstmt close
server demohdbc disconnect

Thanks also to Darrell Connelly, David Andrews, Ole Gregor, and
David Cautley!
-- 
- Bill Thoen
------------------------------------------------------------ 
GISnet, 1401 Walnut St., Suite C, Boulder, CO  80302
tel: 303-786-9961, fax: 303-443-4856
mailto:[EMAIL PROTECTED], http://www.gisnet.com/
------------------------------------------------------------



_______________________________________________________________________
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, send e-mail to [EMAIL PROTECTED] and
put "unsubscribe MapInfo-L" in the message body.

Reply via email to