Check if table exists on IBM As400 database using Vb.net sql statement

  • I'm trying to check if a table exist on my IBM As400 database.

    I'm using Vb.net to create an application, which runs sql statements and sends them via an ODBC connection to the AS400.

    99% of my app works, but I want to be able to check if a table exist before running any SQL's.

    I've seen some examples on the net and in the forums such as the following:

    --===== If the test table already exists, drop it IF OBJECT_ID('TempDB..#mytable','U') IS NOT NULL DROP TABLE #mytable

    However, I'm not sure if my OBJECT_ID is not set properly or IBM doesn't like some of the commands being sent to it.

    For instance in my create table statement I do the following:

    query = "CREATE TABLE " & tmptable _

    & " (PRPROP CHAR(30) CCSID 37 DEFAULT NULL, " _

    etc......

    ODBC_SQL()

    Private Sub ODBC_SQL()

    ODBC_DataAdapter = New Odbc.OdbcDataAdapter(ODBC_Command)

    ODBC_DataAdapter.SelectCommand = New System.Data.Odbc.OdbcCommand(query, ODBC_connect)

    Cama_tbl.Reset()

    ODBC_DataAdapter.Fill(DataSet, "Cama_tbl")

    End Sub

    My create table statement works fine, and if I add a "DROP" table statement it works too. However, I basically want to check if the table exist first before I create the table so I won't get any error messages.

    Any help is appreciated.

    Eddie

  • Sorry dude, this is not an IBM forum. I would suggest trying one of those. You may have better luck.

    Watch my free SQL Server Tutorials at:
    http://MidnightDBA.com
    Blog Author of:
    DBA Rant – http://www.MidnightDBA.com/DBARant

    Minion Maintenance is FREE:

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply