views:

825

answers:

2

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).

A: 

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.

Diodeus
+4  A: 

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()
KiwiBastard