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.