Re: Best way to rename column in Access database file

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Paul, thank you for such a prompt response. Firstly, here's the code in C#:

ADOX.Catalog cat = new ADOX.Catalog();
ADODB.Connection ADOconn = new ADODB.Connection();
ADOconn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Jet OLEDB:Engine Type=5", "admin", "", 0);
cat.ActiveConnection = ADOconn;
cat.Tables["tablename"].Columns["oldcolname"].Name = "newcolname";
ADOconn.Close();
cat.ActiveConnection = null;

The thing is the Connection.Open has really four parameters here, intellisense tooltip says this:

"void _Connection.Open(string ConnectionString, string UserID, string Password, int Options)"

No overloads, just this one with four parameters. Also, Catalog.ActiveConnection does not contain Close() here. That's why I had to
close the connection directly through ADODB.Connection.

As for the question 1: since I could successfully build the solution a few moments later I was able to check how the above-mentioned
code works. Everything was fine and no table had to be added into the Catalog. The zero supplied as Options is probably OK. Anyway,
I will google it once more and hopefully find some information about this parameter.

Question 2: I've noticed two DLLs appeared in the bin folder with compiled solution. These DLLs are Interop.ADODB.dll and
Interop.ADOX.dll. Correct question would probably be: Do I have to copy these two DLLs to the folder with my application everywhere
I install it? Isn't there a way to "embed" them into the compiled EXE? In case I copied the application to some folder without those
two files and run it, everything was fine, except when I tried to rename some column an error message saying "... component
Interop.ADOX.dll <version info> could not be loaded." appeared and (obviously) column was not renamed.

I'm sorry for my English, it probably makes the text much more confusing.

With regards
nvx


Paul Clement napsal(a):
On Fri, 04 Aug 2006 18:16:10 +0200, nvx <nvx@xxxxxxxxxxxxx> wrote:

¤ Hi Paul,
¤ thank you very much for your reply. I code in C#.NET (VC# 2005 Express Edition) and I'm a beginner, so it took me a while even
¤ to reference the ADOX, ADODB and define the catalog and connection. Opening the connection required four parameters,
¤ meaning of three of them was obvious, but I didn't know what to supply as Options (integer value) so I've put zero there.
¤ Could you please clarify the meaning of this parameter a bit?
¤
¤ Two more things:
¤ 1. Do I need to add the tables etc. into the catalog myself or will that be done automatically after executing something similar to
¤ DataAdapter.Fill()?
¤ 2. Do I have to install any additional software on the machine my application will run on?
¤
¤ Thank you in advance.
¤

OK, I'm not sure if I understand your questions. The connection string is rather basic. The only
thing you need to change is the database location (Data Source). You don't need to change the
Provider string or the Jet OLEDB Engine Time value. As a matter of fact you can omit the Jet
OLEDB:Engine Type if your wish.

Regarding your additional questions, I'm not sure what you're asking in question 1 and how it
relates to renaming a column. Could you be a bit more specific?


Paul
~~~~
Microsoft MVP (Visual Basic)
.



Relevant Pages

  • Re: How to SELECT UNION data from two Excel files???
    ... Thanks for helping, Paul. ... connection can not be used to perform this operation. ... > ¤ Using vbscript and ADO, I would like to know how to... ... > Dim cnn As New ADODB.Connection ...
    (microsoft.public.vb.database.ado)
  • Re: Alternative to using DSN to connect to database
    ... system administrator managing the .NET environment for a new application. ... server administrator configures the connection pools and connection ... Was the external config file containing the username and password the only ... >> ¤ ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Connection question
    ... recordset using the connection, the record count property was -1. ... How do I specify the cursor location propery in the connection string? ... > ¤ Hello, ... The object being that I want the connection to fail if the database is ...
    (microsoft.public.vb.database.ado)
  • Re: Alternative to using DSN to connect to database
    ... I have to admit though my views on storing passwords are ... I don't store UserID's and Passwords ever unless it is a server ... You can store your connection string in a config file, ... >> ¤ ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Alternative to using DSN to connect to database
    ... You can store your connection string in a config file, ... you needn't worry about server name changes. ... > ¤ I know that this question has been asked alot but I have seen no direct ...
    (microsoft.public.dotnet.framework.adonet)