473,769 Members | 8,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

add a colmn to an existing table using ADO

I need to add a column to a table using code.

The following works, but only for a new table. How should I change this to
alter an existing table?
Dim strConn
Dim Catalog As New ADOX.Catalog
Dim Table As ADOX.Table

Set Catalog = New ADOX.Catalog

strConn = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=C:\Data. mde"
Catalog.ActiveC onnection = strConn

Set Table = New ADOX.Table
Table.Name = "tblExistingTab le"
Table.Columns.A ppend "NewColumn" , adBoolean
Catalog.Tables. Append Table

Nov 12 '05 #1
4 2275

Użytkownik "da**@strategic delivery.co.nz" <st************ ***@ihug.co.nz>
napisał w wiadomości
I need to add a column to a table using code.


Hi!

Private Sub OnButton_Click( )
Dim sql As String
sql = "ALTER TABLE MyTable ADD MyField Text NULL"
DoCmd.RunSQL sql
End Sub

I'm sure you don't need more code ;)

Regards, Leon!
Nov 12 '05 #2

Użytkownik "Leon" <et**@op.pl> napisał w wiadomości
news:bu******** **@news.onet.pl ...

Użytkownik "da**@strategic delivery.co.nz" <st************ ***@ihug.co.nz>
napisał w wiadomości
I need to add a column to a table using code.


Hi!

Private Sub OnButton_Click( )
Dim sql As String
sql = "ALTER TABLE MyTable ADD MyField Text NULL"
DoCmd.RunSQL sql
End Sub


Soooorrryyyyy ;) ADO correction ;)

Private Sub OnButton_Click( )
Dim sql As String
sql = "ALTER TABLE MyTable ADD MyField Text NULL"
CurrentProject. Connection.Exec ute sql
End Sub

My mistake ;)
Nov 12 '05 #3
Leon

Thanks for that - it works perfectly for a local database

How would I use it to connect to

strConn = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=C:\Data. mde"

Dave
"Leon" <et**@op.pl> wrote in message news:bu******** **@news.onet.pl ...

Użytkownik "Leon" <et**@op.pl> napisał w wiadomości
news:bu******** **@news.onet.pl ...

Użytkownik "da**@strategic delivery.co.nz" <st************ ***@ihug.co.nz>
napisał w wiadomości
I need to add a column to a table using code.


Hi!

Private Sub OnButton_Click( )
Dim sql As String
sql = "ALTER TABLE MyTable ADD MyField Text NULL"
DoCmd.RunSQL sql
End Sub


Soooorrryyyyy ;) ADO correction ;)

Private Sub OnButton_Click( )
Dim sql As String
sql = "ALTER TABLE MyTable ADD MyField Text NULL"
CurrentProject. Connection.Exec ute sql
End Sub

My mistake ;)

Nov 12 '05 #4
Sorry I have some problems with posting :/

Here is general case:

Private Sub OnButton_Click( )
Dim cnn as ADODB.Connectio n
Dim sql As String
Dim strConn As String

strConn = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=C:\Data. mde"
Set cnn = New ADODB.Connectio n

cnn.Open strConn, USERID, PASSWORD

sql = "ALTER TABLE MyTable ADD MyField Text NULL"
cnn.Execute sql

End Sub

Regards, Leon!
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6581
by: dev | last post by:
how create a temp table as a copy of a existing table and then update1 field and insert the hole temp table back in the existing table? please any help? if i have 10 fields in 1 record and about 100 records and a field.status=1 in a existing_table and i want to create a temp_table with all the recordse and values of the existing_table and then update the field.status to 2 and insert in 1 query the temp_table in the existing_table
3
2375
by: Bennett Haselton | last post by:
I'm working on an ASP.Net project where I want to test code on a local machine using a local database as a back-end, and then export it to the production machine where it uses the hosting provider's SQL Server database on the back-end. Is there a way to export tables from one SQL Server database to another in such a way that if a table already exists in the destination database, it will be updated to reflect the changes to the local...
11
4856
by: Randell D. | last post by:
Folks, I have a table of addresses and a seperate table with contact names - All addresses tie to one or more names - I would like to keep track of the number of names 'belonging' to an address and have thus included a column in my address table called num_of_contacts. Everytime I add a new contact, I would like to increment the num_of_contacts column in the address table. Is this possible?
3
4909
by: Raj | last post by:
Hi, I am trying to add some more information to the table which already has a lot a data (like 2-3000 records). The new information may be adding 2-3 new columns worth. Now my questions are: (1)Is it a good idea to add new columns to the existing table? then it will create these new columns for all old records, will it not result in wasting a lot of space?? (2)Is it a good idea to create a new table with the new information and have as a...
3
53772
by: GL | last post by:
Hi, Is there a way to add a field to an existing table using a query of some sort (without needing to manually add a field to the table). I know how to do it with a make table query, but I have a specific need to only add a new field to a table if possible. Here's a simplified example of what I'm trying to do: I get a file with the following two fields: First Name
5
2959
by: Wayne Wengert | last post by:
I am using VB ASP.NET. In my page I convert an uploaded XML file to a dataset as follows: Dim ds1 As DataSet = New DataSet ds1.ReadXml(strPathName, XmlReadMode.Auto) Now I want to append all the rows of ds1 to an existing table in an SQL Server database. I know I can do things like looping through the dataset and issuing Update SQL statements to do this but I suspect there is a better
2
5720
by: Rahul B | last post by:
Hi. I have created a table CREATE TABLE testschema.player ( country VARCHAR(80) NOT NULL, posn VARCHAR(2) not null ) /
14
10859
by: deejow | last post by:
U guys/gals are awesome! I have a "Claimant Master" table with a primary key called "Claimant ID" set to number data type. It has existing records linked to an enormous "Jobs" table. There are thousands of existing entries and some Claimants have several entries. I want to leave the existing entries untouched and get the database to fill in the Claimant ID automatically from now on. Can this be done? It won't let me change it to autonumber...
1
5170
by: arcingmad | last post by:
Hi I am using the following code in a button click event to run a query stored in a .mdb file from an external geographic program ArcGIS via a jet adodb connection I have the need to run an existing make table query, my problem is it will over write an existing table. i.e when run in access a warning that you are about to overwrite an existing table will be shown and you will be prompted to accept or reject. When run via the external program...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9998
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.