问题
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).
回答1:
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()
回答2:
Query the table for the field you expect and handle the error if the field is not there.
Too add the column, just feed the database an alter table SQL statement.
来源:https://stackoverflow.com/questions/251560/add-columns-to-an-access-jet-table-from-net