Exists or not?

dil4VB
10-16-2004, 09:53 PM
i am working with databases.

members of this forum have helped me figure out how to create a Database file, and create a table in that database using SQL. :) But in order to avoid errors i need to check the following

1. whether a database exists at a location or not?
2. whether a table exists in a database or not?
3. whether a field exists in a table or not?

how can i do it? :(

P.S. i use SQL statements in code (INSERT INTO, SELECT etc...)

i am just using the code posted by someone in a forum as an answer to my question because i dont know about SQL and Jet databases in detail yet. So please explain your answer to me a bit elaborately.

thanks in advance

MKoslof
10-17-2004, 09:20 AM
What database are you working with? Access, SQL Server, Oracle?.

There are tons of potential ways to do this. Have you tried simply doing a search of the forum..I know you will find a lot of code samples. But for Access:

1) You can use a standard Dir() call to test if the database exists. Access is a flat file system, not a true client/server database like Oracle or SQL Server, all you have to do is look for the file in order to tell if it exists, you can use a function that implements standard File and Directory methods

2) You can use the OpenSchema method of the ADO connection object to get all tables in an Access database, or the ADOX library. Again, if you do a search of the forum, there are a few examples of this.

3) For fields, you can use the fields collection of the recordset object. Just loop until the recordset fields.count - 1 and if you do not find a specific field name within the returned list, the current field name does not exist in the table you opened with your ADO recordset.

dil4VB
10-17-2004, 09:47 AM
sorry i didnt tell i was workin with .mdb files

anyway...

thanks a lot for the help

MKoslof
10-17-2004, 09:49 AM
Once you start coding, if you get stuck, post your current code piece, and we will help you along. Good luck.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum