Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: how to create a simple ODBC database?

  1. #11
    Member
    Join Date
    Mar 2009
    Location
    Netherlands
    Age
    53
    Posts
    248
    Rep Power
    40

    Re: how to create a simple ODBC database?

    Hello Eros,

    It goes very well with setting up a database but somehow I can't update a record with OdbcUpdateRecord.
    The biggest chance is that I am doing something wrong (well, I followed this example: http://www.jose.it-berater.org/smffo...hp?topic=307.0). Although it's so simple that I almost couldn't do anything wrong. So I was thinking there's maybe a bug in ThinBasic itself. If you have some time, could you please check it out for me...?

    Thanks in advance,

    Martin

  2. #12
    Member
    Join Date
    Mar 2009
    Location
    Netherlands
    Age
    53
    Posts
    248
    Rep Power
    40

    Re: how to create a simple ODBC database?

    PROBLEM SOLVED!
    I'm using OdbcSetabsolutePosition before OdbcUpdateRecord and it works fine now!

  3. #13
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    58
    Posts
    3,299
    Rep Power
    348

    Re: how to create a simple ODBC database?

    Martin,

    If you have time for it, could you post a sample which includes creating the database, writing and reading records?

    Michael

  4. #14
    Member
    Join Date
    Mar 2009
    Location
    Netherlands
    Age
    53
    Posts
    248
    Rep Power
    40

    Re: how to create a simple ODBC database?

    Sure, I modified a little bit the scripts earlier posted by Eros.

    It shows how to:
    -create a database
    -create a new table and fields
    -add records
    -read a record
    -update a record
    -delete all records

    see attachment....
    Attached Files Attached Files

  5. #15
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    58
    Posts
    3,299
    Rep Power
    348

    Re: how to create a simple ODBC database?

    Thank you

  6. #16
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736

    Re: how to create a simple ODBC database?

    Thanks,

    very practical example
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  7. #17
    Junior Member
    Join Date
    Jan 2009
    Location
    UK
    Posts
    15
    Rep Power
    17

    How to access a MySQL database using ODBC?

    Hi all,
    The ODBC examples that come with thinBASIC show only how to use it with an MS Access database.

    I have an existing, functional, MySQL database on my Windows 7 desktop, which I would like to use with thinBASIC.

    I have tried to adapt the examples, but without success because, I suspect, I am not using the correct syntax to access the MySQL ODBC driver.

    I have installed the MySQL ODBC 5.1 driver, which I obtained from the MySQL website.
    I can see the driver in the Control Panel/Administrative Tools/Data Sources (ODBC) window, so it appears to have installed correctly. I don't have MS Excel, so I can't easily test if the driver is working or not.

    I used the same syntax as shown in the examples, but simply changed the name of the driver to that of the MySQL one.
    Here is a snippet of code to show what I did...
    [code=thinbasic]


    '---Allocates an environment handle
    hEnv = OdbcAllocEnv
    IF OdbcError THEN
    console_writeline("Script aborted. It was not possible to create an environment handle.")
    Terminate
    Else
    PrintL "Environment handle created OK.":PrintL
    end if


    '---Allocates the connection handle
    hDbc = OdbcAllocConnect(hEnv)
    IF ISFALSE hDbc THEN
    console_writeline("Script aborted. It was not possible to allocate the connection handle.")
    Terminate
    Else
    PrintL "Connection handle created OK.":PrintL
    end if

    '---Connects with the ODBC driver
    'Immediately below is the original version of the ConStr for the MS Access driver...
    'ConStr = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=biblio.mdb;UID=;PWD=;"
    'Immediately below is my new version of the ConStr string....
    ConStr = "DRIVER={MySQL ODBC 5.1 Driver};DBQ=databasename;UID=localhost;PWD=password;"
    OdbcOpenConnection(hDbc, ConStr)
    IF OdbcError THEN
    console_writeline(OdbcGetConnectionErrorInfo(hDbc))
    Terminate
    Else
    PrintL "ODBC connection handle created OK.":PrintL
    END IF

    [/code]

    Of course, the 'databasename' and 'password' placeholders have been amended to hide the real versions.
    I get the following result...

    >>Environment handle created OK

    >>Connection handle created OK

    >>SqlState: IM008
    >>Native error: 0
    >>[MySQL][ODBC 5.1 Driver]Invalid window handle

    Could any kind person, experienced in using MySQL, please help?

    TIA
    John

  8. #18
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

    Re: how to create a simple ODBC database?

    I've never used MySQL ODBC connection but checking at http://www.connectionstrings.com/mysql
    under "MySQL Connector/ODBC 5.1" and comparing to your connection string you specified "DBQ=" while in the example is used "Database="

    So connection string can looks like
    "Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=myDataBase; User=myUsername;Password=myPassword;Option=3;"

    Try to change it and see if it makes any difference.

    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  9. #19
    Junior Member
    Join Date
    Jan 2009
    Location
    UK
    Posts
    15
    Rep Power
    17

    Re: how to create a simple ODBC database?

    Eros,

    Very many thanks for your prompt response...very impressive!

    I tried out your suggested connection string and .... it worked right away !!

    You have opened up a whole new world to me now.
    I can now explore my data in a much more flexible way than using just SQL alone.

    I am really grateful.
    Long live thinBASIC and Eros!

    Thank you

    JohnP

  10. #20
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

    Re: how to create a simple ODBC database?

    Great.
    I just guessed
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Alternative for ODBC Database
    By martin in forum thinBasic General
    Replies: 34
    Last Post: 29-08-2009, 08:17

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •