Search code examples
.netdatabasems-accessjet

Add columns to an Access (Jet) table from .NET


Our app (already deployed) is using an Access/Jet database. The upcoming version of our software requires some additional columns in one of the tables. I need to first check if these columns exist, and then add them if they don't.

Can someone provide a quick code sample, link, or nudge in the right direction?

(I'm using c#, but a VB.NET sample would be fine, too).


Solution

  • Off the top of my head, but something like:

    Dim conn as New AdoConnection(someConnStr)
    Dim cmd as New AdoCommand
    cmd.Connection = conn
    cmd.CommandText = "ALTER TABLE X ADD COLUMN y COLUMNTYPE"
    cmd.ComandType = CommandType.Text
    cmd.ExecuteNonQuery()