473,406 Members | 2,849 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Is there a way to insert Queries programmatically?

3
I'm using Access 2000, but this question likely pertains to any version of Access. Simply put, is there a programmatic way of inserting a new Query in whatever master system table stores these (maybe QueryDefs?), so I wouldn't have to use the IDE and open Access to do it?

Here's more information if that helps: I can open Access itself and create a Query. I can save it and name it something meaningful. I can then execute that query just by double-clicking on it from within Access. But better yet, I can execute that query programatically via VB, ASP.NET, etc.

Meanwhile, my database naturally has data tables where I can insert records also programatically, with either SQL INSERT statements directly in my ASP.NET code or by calling stored queries that perform INSERT actions and passing parameters. This is typical for displaying an insert form on a web page and having the user fill out fields and then the code inserts a new record into the database table(s) as needed.

However, I occasionally want to add more stored queries to my Access database that has already been uploaded to my web host server and updated by various people. In the past, I've been bringing down the site for maintenance, downloading the entire Access .mdb file locally, adding my new stored queries, and reuploading the entire Access .mdb to the server, then bringing my site back up for use.

However, this would all be much easier and quicker if I could create an "admin" page where only I log in and I could create my own new stored queries in SQL, just as if I were using the Access IDE, and my code would then insert them into whatever system table stores these, etc. I just don't know the name of the table, its structure, and/or whether this would be possible.

I hope this makes sense. And while I don't think I'm the first person to want to do this, I did try to search high and low on your forum and other places on the Net and couldn't find anything that addressed this. Please forgive me if I just overlooked it in your numerous FAQs and Tutorials, etc.

Thanks.
Jul 16 '07 #1
5 4438
ADezii
8,834 Expert 8TB
I'm using Access 2000, but this question likely pertains to any version of Access. Simply put, is there a programmatic way of inserting a new Query in whatever master system table stores these (maybe QueryDefs?), so I wouldn't have to use the IDE and open Access to do it?

Here's more information if that helps: I can open Access itself and create a Query. I can save it and name it something meaningful. I can then execute that query just by double-clicking on it from within Access. But better yet, I can execute that query programatically via VB, ASP.NET, etc.

Meanwhile, my database naturally has data tables where I can insert records also programatically, with either SQL INSERT statements directly in my ASP.NET code or by calling stored queries that perform INSERT actions and passing parameters. This is typical for displaying an insert form on a web page and having the user fill out fields and then the code inserts a new record into the database table(s) as needed.

However, I occasionally want to add more stored queries to my Access database that has already been uploaded to my web host server and updated by various people. In the past, I've been bringing down the site for maintenance, downloading the entire Access .mdb file locally, adding my new stored queries, and reuploading the entire Access .mdb to the server, then bringing my site back up for use.

However, this would all be much easier and quicker if I could create an "admin" page where only I log in and I could create my own new stored queries in SQL, just as if I were using the Access IDE, and my code would then insert them into whatever system table stores these, etc. I just don't know the name of the table, its structure, and/or whether this would be possible.

I hope this makes sense. And while I don't think I'm the first person to want to do this, I did try to search high and low on your forum and other places on the Net and couldn't find anything that addressed this. Please forgive me if I just overlooked it in your numerous FAQs and Tutorials, etc.

Thanks.
First things first:
  1. Tools ==> Options ==> View Tab ==> Under the Show Section ==> Check System Objects.
  2. The above sequence will turn ON the display of System Objects, in your case System Tables, in the Database Window.
  3. To the best of my knowledge, Query related information is stored in 2 System Tables, namely: MSysObjects and MSysQueries.
  4. In my humble opinion, trying to create Queries and save them directly to the System Tables bypassing the Access GUI, would be a daunting task to say the least. I'm not even sure if this is possible.
  5. It seems as though Microsoft does not provide any documentation on the format of these System Tables, since direct manipulation can cause disastrous results. I imagine that it would be analogous to directly manipulating the System Registry.
  6. Hope this helps a little - should you ever actually implement your ideas, please let us know since I'm sure that many of our Moderators/Experts would be very interested in how you accomplished this task.
  7. Good luck in your venture.
Jul 17 '07 #2
DonnaL
3
Thanks for your reply. In looking at those two System tables and experimenting with a few new queries, I could probably guess at many of the fields and rows that I would need, but some fields are storing LOBs and that just raises a red flag for me.

I'm dealing with CLOBs in Oracle at work and I really don't need to learn the Access way of the comparable binary objects just for my simple little application. I'll do it the old-fashioned way and create new queries through the IDE and reupload my .mdb each time.

It just seemed like it would be a nifty way to do something advanced, but like you implied (or said), Microsoft undoubtedly keeps a lot of this secret since they don't want people messing with System tables that could cause other problems.

Thanks again. If I ever do revisit this topic and find a way to do it, I'll post it.
Jul 18 '07 #3
ADezii
8,834 Expert 8TB
Thanks for your reply. In looking at those two System tables and experimenting with a few new queries, I could probably guess at many of the fields and rows that I would need, but some fields are storing LOBs and that just raises a red flag for me.

I'm dealing with CLOBs in Oracle at work and I really don't need to learn the Access way of the comparable binary objects just for my simple little application. I'll do it the old-fashioned way and create new queries through the IDE and reupload my .mdb each time.

It just seemed like it would be a nifty way to do something advanced, but like you implied (or said), Microsoft undoubtedly keeps a lot of this secret since they don't want people messing with System tables that could cause other problems.

Thanks again. If I ever do revisit this topic and find a way to do it, I'll post it.
You're quite welcome.
Jul 18 '07 #4
Hi!

You can do this by ADOX:

Add Reference: COM: "Microsoft ADO Ext. 2.x for DDL and Security"
Add Reference: .NET: adodb
Expand|Select|Wrap|Line Numbers
  1. using ADOX;
  2. using ADODB;
  3.  
  4. namespace X
  5. {
  6.     class a
  7.     {
  8.         public void b()
  9.         {
  10.             string connectionString = "Provider='Microsoft.Jet.OLEDB.4.0'; Data  Source='c.mdb'";
  11.             ADOX.CatalogClass cat = new ADOX.CatalogClass();
  12.             ADODB.Connection connection = new ADODB.ConnectionClass();
  13.             connection.Open(connectionString, "", "", 0);
  14.             cat.ActiveConnection = connection;
  15.  
  16.             StringBuilder sb = new StringBuilder ();
  17.             CommandClass command = new CommandClass();
  18.             command.CommandType = ADODB.CommandTypeEnum.adCmdText;
  19.             command.CommandText = GetQueryCommandText();
  20.             cat.Procedures.Append("Query", command);
  21.             connection.Close();
  22.             cat = null;
  23.         }
  24.     }
  25. }
  26.  
If you like ADOX. You can even build a brand new Access Database with ADOX.

Cheers

Ralf

I'm using Access 2000, but this question likely pertains to any version of Access. Simply put, is there a programmatic way of inserting a new Query in whatever master system table stores these (maybe QueryDefs?), so I wouldn't have to use the IDE and open Access to do it?

Here's more information if that helps: I can open Access itself and create a Query. I can save it and name it something meaningful. I can then execute that query just by double-clicking on it from within Access. But better yet, I can execute that query programatically via VB, ASP.NET, etc.

Meanwhile, my database naturally has data tables where I can insert records also programatically, with either SQL INSERT statements directly in my ASP.NET code or by calling stored queries that perform INSERT actions and passing parameters. This is typical for displaying an insert form on a web page and having the user fill out fields and then the code inserts a new record into the database table(s) as needed.

However, I occasionally want to add more stored queries to my Access database that has already been uploaded to my web host server and updated by various people. In the past, I've been bringing down the site for maintenance, downloading the entire Access .mdb file locally, adding my new stored queries, and reuploading the entire Access .mdb to the server, then bringing my site back up for use.

However, this would all be much easier and quicker if I could create an "admin" page where only I log in and I could create my own new stored queries in SQL, just as if I were using the Access IDE, and my code would then insert them into whatever system table stores these, etc. I just don't know the name of the table, its structure, and/or whether this would be possible.

I hope this makes sense. And while I don't think I'm the first person to want to do this, I did try to search high and low on your forum and other places on the Net and couldn't find anything that addressed this. Please forgive me if I just overlooked it in your numerous FAQs and Tutorials, etc.

Thanks.
Aug 2 '07 #5
Hi!

Explanation in German, samples in English, language of samples VB:

http://www.activevb.de/tutorials/tut_adox/adox.html

It's good to get some ideas ;-)

Have fun

Ralf


Hi!

You can do this by ADOX:

Add Reference: COM: "Microsoft ADO Ext. 2.x for DDL and Security"
Add Reference: .NET: adodb
Expand|Select|Wrap|Line Numbers
  1. using ADOX;
  2. using ADODB;
  3.  
  4. namespace X
  5. {
  6.     class a
  7.     {
  8.         public void b()
  9.         {
  10.             string connectionString = "Provider='Microsoft.Jet.OLEDB.4.0'; Data  Source='c.mdb'";
  11.             ADOX.CatalogClass cat = new ADOX.CatalogClass();
  12.             ADODB.Connection connection = new ADODB.ConnectionClass();
  13.             connection.Open(connectionString, "", "", 0);
  14.             cat.ActiveConnection = connection;
  15.  
  16.             StringBuilder sb = new StringBuilder ();
  17.             CommandClass command = new CommandClass();
  18.             command.CommandType = ADODB.CommandTypeEnum.adCmdText;
  19.             command.CommandText = GetQueryCommandText();
  20.             cat.Procedures.Append("Query", command);
  21.             connection.Close();
  22.             cat = null;
  23.         }
  24.     }
  25. }
  26.  
If you like ADOX. You can even build a brand new Access Database with ADOX.

Cheers

Ralf
Aug 7 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
8
by: Kragen Sitaker | last post by:
ERROR: Cannot insert a duplicate key into unique index pg_class_relname_nsp_index We've been getting this error in our application every once in a while --- typically once an hour to once a day,...
1
by: Lumpierbritches | last post by:
Thank you in advance. Is there a way to programmatically fill an Unbound Form with a command button, using Queries built? I have a program that has about 10 different queries that all fill the...
11
by: Gord D via AccessMonster.com | last post by:
I have a small ASP website with an Access2000 database. Seems someone has found it and INSERTS records into a table by typing the URL and not via web page/form. I know this as I have some...
9
by: Jack | last post by:
Hi, I am gathering the input values to a form using Request.form method from the processing page. After all the data is captured, I am building sql statement out of it. Using a response.write...
3
by: Bob Bedford | last post by:
hello I'm looking for some functions or objects allowing to select-insert-update-delete from any table in a mysql database without the need to create a new query every time. Example: ...
11
by: Eugene Anthony | last post by:
The code bellow functions well when I attemp to delete a record. But when I attemp to insert a record I am getting the following error -2147217900:Syntax error in INSERT INTO statement. How do I...
3
by: Dave | last post by:
I have an old web app that ues an Access database and ASP 3.0. I need to build an INSERT statement based on the contents of a form. What is the best way to handle blank text boxes that are...
2
by: paulmitchell507 | last post by:
I think I am attempting a simple procedure but I just can't figure out the correct syntax. My asp (classic) page runs a SELECT query to obtain dates and ID's from 2 tables uSQL = "SELECT...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.