Closed Thread
Results 1 to 2 of 2

Thread: ALTER Queries to Access trough VB.NET

  1. #1
    penkomitev is offline Learning Programmer
    Join Date
    Dec 2007
    Location
    Plovdiv, Bulgaria
    Posts
    31
    Rep Power
    0

    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

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    penkomitev is offline Learning Programmer
    Join Date
    Dec 2007
    Location
    Plovdiv, Bulgaria
    Posts
    31
    Rep Power
    0
    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

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Virus queries
    By kylelendo in forum General Programming
    Replies: 9
    Last Post: 08-25-2011, 05:28 PM
  2. Replies: 0
    Last Post: 10-24-2010, 01:14 PM
  3. Help appreciated with forms and queries in Access
    By alexbabwa in forum Database & Database Programming
    Replies: 4
    Last Post: 03-21-2010, 11:15 PM
  4. SQL INSERT Queries
    By chili5 in forum Tutorials
    Replies: 2
    Last Post: 09-05-2009, 06:59 AM
  5. Alter many files, all with same variable in them
    By woocha in forum PHP Development
    Replies: 3
    Last Post: 01-17-2008, 04:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts