Lost Password?


Go Back   CodeCall Programming Forum > Software Development > Visual Basic Programming

Visual Basic Programming Discussion forum for Visual Basic, an event driven programming language and associated development environment from Microsoft for its COM programming model.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-02-2008, 10:24 AM
penkomitev penkomitev is offline
Learning Programmer
 
Join Date: Dec 2007
Location: Plovdiv, Bulgaria
Age: 16
Posts: 30
Rep Power: 4
penkomitev is on a distinguished road
Send a message via ICQ to penkomitev Send a message via Skype™ to penkomitev
Default ALTER Queries to Access trough VB.NET

Hello,
I managed to execute queries like SELECT * FROM a, but I cannot execute the ones with ALTER, because the following error appear: Cannot execute data definition statements on linked data sources.

I read something about Back-end & Front-end queries(they are different), but at end I didn't succeed. I've tried 15 different source codes and each with problems.
The last I tried is:

Code:
        Dim strConnectionString As String

        strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & file_path

        Dim oConnection As New System.Data.OleDb.OleDbConnection(strConnectionString)

        oConnection.Open()

        Dim oCommand As System.Data.OleDb.OleDbCommand

        oCommand = oConnection.CreateCommand()

        oCommand.CommandText = "Alter Table procProductsList Add NewColumn Text"

        oCommand.ExecuteNonQuery()
It is just very strange how it does not want to work and what would be the other sollution, that I haven't tried. I've tried this one too:

Code:
  Cn = New ADODB.Connection
        Cat = New ADOX.Catalog
        objTable = New ADOX.Table

        'Open the connection
        Cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & file_path)

        'Open the Catalog
        Cat.ActiveConnection = Cn

        'Create the table


        objTable.Name = "procProductsList"
        objTable.Columns.Append("LastName", ADOX.DataTypeEnum.adVarWChar, 40)
        objTable.Columns.Append("ID", ADOX.DataTypeEnum.adInteger)
        objTable.Columns.Append("Department", ADOX.DataTypeEnum.adVarWChar, 20)

        ''append tables to database
        ADOXcatalog.Tables.Append(ADOXtable)
        Append the newly created table to the Tables Collection
        Cat.Tables.Append(objTable)


        ' clean up objects
        'objKey = Nothing
         objTable = Nothing
         Cat = Nothing
         Cn.Close()
        Cn = Nothing
The problem with it is that it is used only for new table to the current database and I cannot decide how to change it so it can be used to update a database, which
already exists before that moment. The error in this case is "Database already exists", which is enough proof that the script tries to create the database, not to update it.

I forgot to say(maybe only in the title) that I am using VB.NET.
__________________
You can visit something interesting HERE
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 02-04-2008, 01:06 PM
penkomitev penkomitev is offline
Learning Programmer
 
Join Date: Dec 2007
Location: Plovdiv, Bulgaria
Age: 16
Posts: 30
Rep Power: 4
penkomitev is on a distinguished road
Send a message via ICQ to penkomitev Send a message via Skype™ to penkomitev
Default

I am a bit surprised nobody answered my topic, but I can at last say that I managed to solve the problem. After reading in the ADO specification on the Microsoft site, I found out that it is known that ALTER queries are not supported. Therefore, I started to look for different codes, which can solve it. After whole, I had to use ADOX for creating new table with the old fields and the ones I need. Then to transfer all the data from the old to the new. After that, I have to delete the old one and rename the new one with the name of the old. This operation does not take long as my tables are not with more than 250-300 records. If someone is interested in the snippet I used, just write me.
__________________
You can visit something interesting HERE
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Java:Tutorial - Access Modifiers John Java Tutorials 0 12-09-2006 10:57 AM


All times are GMT -5. The time now is 02:15 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads