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

寵の児 提交于 2019-12-13 20:19:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!